def pers_to_db(itemsoup,ref_dict): '''Extract a person from XML and write it into the database.''' p = Person() if hasattr(itemsoup, 'person-header'): header = itemsoup.find('person-header') pers_name = header.person.persname p.name=itemsoup['value'] p.additional_names = if_exists(pers_name.addNames) p.forename = if_exists(pers_name.forename) p.surname = if_exists(pers_name.surname) p.maidenname = if_exists(pers_name.maidenname) p.rolename = if_exists(pers_name.rolename) p.genname = if_exists(pers_name.genname) p.description = if_exists(header.person.description) p.id = get_item_ID() p.xml_repr = itemsoup p.save() # Mentionings + related index entries ment_to_db(itemsoup.find('person-header'), p) ref_dict[p.id] = header.find('index-refs') # Related concepts if hasattr(itemsoup, 'concept-body'): add_all(p.related_concepts, relconc_to_db(itemsoup.find\ ('concept-body').find('related-concepts'))) print (p) return p else: exit()
def create_person(xmlNode): ''' Build a person from XML. Write it into the database.''' global idConc p = Person() pers_name = xmlNode.persname p.name = pers_name.get_text().strip() p.additional_names = if_exists(pers_name.addNames) p.forename = if_exists(pers_name.forename) p.surname = if_exists(pers_name.surname) p.maidenname = if_exists(pers_name.maidenname) p.rolename = if_exists(pers_name.rolename) p.genname = if_exists(pers_name.genname) p.description = if_exists(xmlNode.description) p.id = idConc idConc += 1 p.save() return p