def return_individual_gedcom(self): ''' This function will return the gedcom type individual ''' individual = gedcom.Individual() if "gender" in self.gen_data.keys(): sex = gedcom.Element(tag="SEX", value=self.getGender()) individual.add_child_element(sex) name = gedcom.Element(tag="NAME", value=(self.getName() + "/" + self.getSurname() + "/")) name_given = gedcom.Element(tag="GIVN", value=self.getName()) name_surname = gedcom.Element(tag="SURN", value=self.getSurname()) nick = "" for nickname in self.gen_data.get("nicknames", None): if nick != "": nick += "," nick += nickname name.add_child_element(name_given) name.add_child_element(name_surname) if (nick != ""): name_nickname = gedcom.Element(tag="NICK", value=nick) name.add_child_element(name_nickname) individual.add_child_element(name) #Review all dates to include for date_key in EQUIVALENCE.keys(): include_date, ged_event = self.get_event_element(date_key) if include_date: individual.add_child_element(ged_event) return individual
def create_family(self, husband, wife, children): ''' Creates a family inside the gedcomfile, it only creates the family, all individuals should have been already included Inputs shall be gedcom_profiles format, children shall be a list ''' ged_family = self.family() #Let's create the different elements for our Family ged_husband = gedcom.Element(tag="HUSB", value=husband.return_id()) ged_family.add_child_element(ged_husband) ged_wife = gedcom.Element(tag="WIFE", value=wife.return_id()) ged_family.add_child_element(ged_wife) for child in children: ged_child = gedcom.Element(tag="CHIL", value=child.return_id()) ged_family.add_child_element(ged_child) include_marr, ged_marr = husband.get_event_element("marriage") if include_marr: ged_family.add_child_element(ged_marr)
def test_creating_gedcom_profile(self): ''' Test Creating a GedCom Profile ''' name_data = "MyName" surname = "MySurname" total_name = name_data + "/" + surname + "/" individual = gedcom.Individual() name = gedcom.Element(tag="NAME", value=total_name) name_given = gedcom.Element(tag="GIVN", value=name_data) name_surname = gedcom.Element(tag="SURN", value=surname) name.add_child_element(name_given) name.add_child_element(name_surname) individual.add_child_element(name) profile = gedcom_profile(individual) assert (profile.gen_data["name"] == name_data) assert (profile.gen_data["surname"] == surname)
def get_event_element(self, date_key): ''' Function that provides the event value as an element ''' date = self.gen_data.get(common_profile.ALL_EVENT_DATA[date_key]["date"], None) accuracy = self.gen_data.get(common_profile.ALL_EVENT_DATA[date_key]["accuracy"], None) include_date = False ged_event = gedcom.Element(tag=EQUIVALENCE[date_key], value="") #Ok, we have a date defined, let's create the relevant element if (date): include_date = True ged_date_string = "" full_date = date.strftime("%d %b %Y").upper() if accuracy == "ABOUT": ged_date_string = "ABT " + str(date.year) elif accuracy == "EXACT": ged_date_string = full_date elif accuracy == "BEFORE" : ged_date_string = "BEF " + full_date elif accuracy == "AFTER" : ged_date_string = "AFT " + full_date ged_date = gedcom.Element(tag="DATE", value=ged_date_string) ged_event.add_child_element(ged_date) #Review of the location data location = self.gen_data.get(common_profile.ALL_EVENT_DATA[date_key]["location"], {}) if (any(location)): include_date = True ged_loc = gedcom.Element(tag="ADDR", value="") if "raw" in location.keys(): ged_event_plac = gedcom.Element(tag="PLAC", value=location["raw"]) ged_event.add_child_element(ged_event_plac) for loc_key in LOCATION_EQUIVALENCE.keys(): #Ok, this data is available, let's use it! if loc_key in location.keys(): ged_new_loc_data = gedcom.Element(tag=LOCATION_EQUIVALENCE[loc_key], value=location[loc_key]) ged_loc.add_child_element(ged_new_loc_data) ged_event.add_child_element(ged_loc) return include_date, ged_event
def get_event_element(self, date_key): ''' Function that provides the event value as an element ''' date_event = self.gen_data.get(date_key, None) include_date = False ged_event = gedcom.Element(tag=EQUIVALENCE[date_key], value="") #Ok, we have a date defined, let's create the relevant element if (date_event): include_date = True ged_date_string = "" full_date = date_event.get_gedcom_date() if date_event.get_accuracy() == "ABOUT": ged_date_string = "ABT " + full_date elif date_event.get_accuracy() == "EXACT": ged_date_string = full_date elif date_event.get_accuracy() == "BEFORE": ged_date_string = "BEF " + full_date elif date_event.get_accuracy() == "AFTER": ged_date_string = "AFT " + full_date ged_date = gedcom.Element(tag="DATE", value=ged_date_string) ged_event.add_child_element(ged_date) #Review of the location data location = date_event.get_location() if location and (any(location)): include_date = True ged_loc = gedcom.Element(tag="ADDR", value="") if "raw" in location.keys(): ged_event_plac = gedcom.Element(tag="PLAC", value=location["raw"]) ged_event.add_child_element(ged_event_plac) elif "formatted_location" in location.keys(): ged_event_plac = gedcom.Element( tag="PLAC", value=location["formatted_location"]) ged_event.add_child_element(ged_event_plac) for loc_key in LOCATION_EQUIVALENCE.keys(): #Ok, this data is available, let's use it! if loc_key in location.keys(): ged_new_loc_data = gedcom.Element( tag=LOCATION_EQUIVALENCE[loc_key], value=location[loc_key]) ged_loc.add_child_element(ged_new_loc_data) ged_event.add_child_element(ged_loc) return include_date, ged_event
def testCanAddFamilyRaw(self): gedcomfile = gedcom.GedcomFile() element = gedcom.Element(tag="FAM") gedcomfile.add_element(element)
def testCanAddIndividualRaw(self): gedcomfile = gedcom.GedcomFile() element = gedcom.Element(tag="INDI") gedcomfile.add_element(element)
def testCanOnlyAddIndividualOrFamilyToFile(self): gedcomfile = gedcom.GedcomFile() title = gedcom.Element(tag="TITL") self.assertRaises(Exception, gedcomfile.add_element, (title))