def get_xml_trees(db, host, pid, usernames, graceful=False):
""" Params: db, host, paragraph id, the list of usernames wanted,
Optional:
graceful: True if no excpetions are to be raised
excpetion raised if a user did not submit an annotation for the passage
returns a list of xml roots elements
"""
cur = get_cursor(db, host)
xmls = []
for username in usernames:
username = str(username) # precaution for cases bad input e.g. 101
cur_uid = get_uid(db, host, username)
cur.execute("SELECT xml FROM xmls WHERE paid=" + PLACE_HOLDER +
" AND uid=" + PLACE_HOLDER + "ORDER BY ts DESC",
(pid, cur_uid))
raw_xml = cur.fetchone()
if not raw_xml and not graceful:
raise Exception("The user " + username +
" did not submit an annotation for this passage")
else:
xmls.append(fromstring(raw_xml[0]))
return xmls
评论列表
文章目录