def test_creating_gedcom_from_common(self): ''' Test creating a GedCom from a common_profile ''' profile = gen_profile("Juana", "Bargas") profile.setCheckedGender("F") profile.add_nickname("Nick1") profile.add_nickname("Nick2") profile.setCheckedDate("birth", 2014, 3, 2, accuracy="EXACT") profile.setCheckedDate("baptism", 2014, 3, 3, accuracy="AFTER") profile.setCheckedDate("death", 2016, 3, 2, accuracy="ABOUT") profile.setCheckedDate("burial", 2016, 3, 5, accuracy="BEFORE") profile.setPlaces("birth", "Portillo,Valladolid,Castile and Leon,Spain", language="es") #We transform to the gedcom class gedcom_profile.convert_gedcom(profile) gedcom_transform = profile.individual for ele in gedcom_transform.__dict__["child_elements"]: if ele.tag == "NAME": for sub_ele in ele.__dict__["child_elements"]: if sub_ele.tag == "GIVN": assert (sub_ele.value == "Juana") if sub_ele.tag == "SURN": assert (sub_ele.value == "Bargas") if sub_ele.tag == "NICK": assert (sub_ele.value == "Nick1,Nick2") elif ele.tag == "SEX": assert (ele.value == "F") elif ele.tag == "BIRT": for sub_ele in ele.__dict__["child_elements"]: if sub_ele.tag == "DATE": assert (sub_ele.value == "02 MAR 2014") if sub_ele.tag == "ADDR": for sub_ele2 in sub_ele.__dict__["child_elements"]: if sub_ele2.tag == "CITY": assert (sub_ele2.value == "Portillo") if sub_ele2.tag == "STAE": assert (sub_ele2.value == "Castilla y León") if sub_ele2.tag == "CTRY": assert (sub_ele2.value == "España") elif ele.tag == "DEAT": for sub_ele in ele.__dict__["child_elements"]: if sub_ele.tag == "DATE": assert (sub_ele.value == "ABT 02 MAR 2016") elif ele.tag == "BAPM": for sub_ele in ele.__dict__["child_elements"]: if sub_ele.tag == "DATE": assert (sub_ele.value == "AFT 03 MAR 2014") elif ele.tag == "BURI": for sub_ele in ele.__dict__["child_elements"]: if sub_ele.tag == "DATE": assert (sub_ele.value == "BEF 05 MAR 2016") gedcomfile = gedcom.GedcomFile() gedcomfile.add_element(profile.individual)
def test_list_profile(self): ''' Test converting a list of profiles into gedcom ''' child1 = gen_profile("Francisco", "Vargas Sanz") child2 = gen_profile("Roberto", "Vargas Sanz") array = [child1, child2] gedcom_profile.convert_gedcom(array) for prof in array: assert (hasattr(prof, 'individual'))
def test_geni_to_gedcom(self): ''' Test a geni profile to Gedcom ''' prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="") assert ("Testing" in prof.nameLifespan()) gedcom_profile.convert_gedcom(prof) location = prof.get_location_event("baptism") #We crosscheck the value is properly included in the file assert ("STAE" in prof.individual["BAPM"]["ADDR"].keys()) assert (location["city"] == "La Mata")
def test_geni_to_gedcom(self): ''' Test a geni profile to Gedcom ''' prof = profile.profile(MAIN_SANDBOX_PROFILE, type_geni="") assert ("Testing" in prof.nameLifespan()) gedcom_profile.convert_gedcom(prof) data_event = prof.get_event_element("birth") element_top = data_event[1] element_sub = element_top.child_elements[1] #We crosscheck the value is properly included in the file assert (element_sub.tag == "PLAC") assert ("Gallegos" in element_sub.value)
def test_output_from_gedcom(self): ''' It will take a gedcom dataclass and perform all executions available ''' profile = gen_profile("Julián", "Gómez Gómez") profile.setCheckedDate("baptism_date", date(1970, 4, 2), "EXACT") profile.setCheckedDate("birth_date", date(1960, 4, 2), "EXACT") profile.setCheckedDate("death_date", date(2017, 2, 12), "EXACT") gedcom_profile.convert_gedcom(profile) new_gedcom = gedcom_file() new_gedcom.add_element(profile.individual) analysis = gen_analyzer(new_gedcom) analysis.execute()
def test_output_from_gedcom(self): ''' It will take a gedcom dataclass and perform all executions available ''' #Just in case the file was created before if os.path.exists(FILE2DELETE): os.remove(FILE2DELETE) if os.path.exists(ROOTS_MAGIC_GEN_ANALYZER): os.remove(ROOTS_MAGIC_GEN_ANALYZER) profile = gen_profile("Julián", "Gómez Gómez") profile.setCheckedDate("baptism", 1970, 4, 2) profile.setCheckedDate("birth", 1960, 4, 2) profile.setCheckedDate("death", 2017, 2, 12) gedcom_profile.convert_gedcom(profile) dbgenea = gen_database() dbgenea.add_profile(profile) profile2 = gedcom_profile(name="Julián", surname="Gómez Gómez") profile2.setCheckedDate("baptism", 1970, 4, 2) profile2.setCheckedDate("birth", 1960, 4, 2) profile2.setCheckedDate("death", 2017, 2, 12) assert ("BIRT" in profile2.individual) dbged = db_gedcom() dbged.add_profile(profile2) #Test that works with RootsMagic input_file = os.path.join(self.filelocation, "RootsMagic_analyzer.rmgc") copyfile(input_file, ROOTS_MAGIC_GEN_ANALYZER) dbroots = database_rm(ROOTS_MAGIC_GEN_ANALYZER) analysis = gen_analyzer() analysis.execute(dbgenea, FILE2DELETE) analysis.execute(dbged) #Threshold will make any analysis to be ignored analysis.execute(dbroots, storage=True, threshold=360) urls = 0 for person in dbroots.get_all_profiles(): urls += len(person.get_all_urls()) assert (urls > 6) assert (os.path.exists(FILE2DELETE)) dbroots.close_db() #We just delete the file once finishes if os.path.exists(FILE2DELETE): os.remove(FILE2DELETE) if os.path.exists(ROOTS_MAGIC_GEN_ANALYZER): os.remove(ROOTS_MAGIC_GEN_ANALYZER)
def test_creating_gedcom_from_common(self): ''' Test creating a GedCom from a common_profile ''' profile = gen_profile("Juana", "Bargas") profile.setCheckedGender("F") profile.add_nickname("Nick1") profile.add_nickname("Nick2") profile.setCheckedDate("birth", 2014, 3, 2, accuracy="EXACT") profile.setCheckedDate("baptism", 2014, 3, 3, accuracy="AFTER") profile.setCheckedDate("death", 2016, 3, 2, accuracy="ABOUT") profile.setCheckedDate("burial", 2016, 3, 5, accuracy="BEFORE") profile.setPlaces("birth", "Portillo,Valladolid,Spain") #We transform to the gedcom class gedcom_profile.convert_gedcom(profile) assert (profile.getGender() == "F") assert (profile.getName() == "Juana") assert (profile.getSurname() == "Bargas") assert (profile.get_specific_event("birth").get_date() == date( 2014, 3, 2)) assert (profile.get_specific_event("death").get_date() == date( 2016, 3, 2)) assert (profile.get_specific_event("baptism").get_date() == date( 2014, 3, 3)) assert (profile.get_specific_event("burial").get_date() == date( 2016, 3, 5)) assert (profile.get_specific_event("birth").get_accuracy() == "EXACT") assert (profile.get_specific_event("death").get_accuracy() == "ABOUT") assert ( profile.get_specific_event("baptism").get_accuracy() == "AFTER") assert ( profile.get_specific_event("burial").get_accuracy() == "BEFORE") assert (profile.get_location_event("birth")["country"] == "Spain") assert ( profile.get_location_event("birth")["place_name"] == "Portillo") #Testing intoducing a list of gedcoms profile2 = gen_profile("Juana", "Bargas") gedcom_profile.convert_gedcom([profile2])
def test_gedcompy_usage(self): ''' Test gedcompy wrapper use ''' date_marr = date(2015, 1, 1) husband = gen_profile("Mario", "Vargas") husband.setCheckedDate("marriage_date", date_marr, "EXACT") wife = gen_profile("María", "Sanz") wife.setCheckedDate("marriage_date", date_marr, "EXACT") child1 = gen_profile("Francisco", "Vargas Sanz") child2 = gen_profile("Roberto", "Vargas Sanz") gedcom_profile.convert_gedcom(husband) gedcom_profile.convert_gedcom(wife) gedcom_profile.convert_gedcom(child1) gedcom_profile.convert_gedcom(child2) new_gedcom = gedcom_file() new_gedcom.add_element(husband.individual) new_gedcom.add_element(wife.individual) new_gedcom.add_element(child1.individual) new_gedcom.add_element(child2.individual) assert (husband.return_id() == "@I1@") assert (wife.return_id() == "@I2@") assert (child1.return_id() == "@I3@") assert (child2.return_id() == "@I4@") new_gedcom.create_family(husband, wife, [child1, child2]) for ele in new_gedcom.__dict__["root_elements"]: if ele.tag == "FAM": for member in ele.__dict__['child_elements']: if (member.tag == "HUSB"): assert (member.value == '@I1@') if (member.tag == "WIFE"): assert (member.value == '@I2@') if (member.tag == "CHILD"): assert (member.value in ['@I3@', '@I4@']) if (member.tag == "MARR"): marr = member.__dict__['child_elements'][0] assert (marr.value == "01 JAN 2015")
def create_gedcom_file(self, output): ''' This function will create the gedcom file that can be read by other genealogical tools ''' if not self.correct_execution: logging.error(NO_GENI_EXECUTION) return False else: new_gedcom = gedcom_file() #We make father and mother a profile gedcom_profile.convert_gedcom(self.father_profile) gedcom_profile.convert_gedcom(self.mother_profile) #We add now the father and mother new_gedcom.add_element(self.father_profile.individual) new_gedcom.add_element(self.mother_profile.individual) #We prepara the children one children_ged = [] for profile_obtained in self.profiles: #We convert the profile into the gedcom profile profile_temp = profile_obtained gedcom_profile.convert_gedcom(profile_temp) new_gedcom.add_element(profile_temp.individual) children_ged.append(profile_temp) if profile_obtained.gen_data.get("marriage_link", None) in self.related_profiles.keys(): id_of_marriage = profile_obtained.gen_data["marriage_link"] #We capture the partner partner = self.related_profiles[id_of_marriage] gedcom_profile.convert_gedcom(partner) #We add the partner new_gedcom.add_element(partner.individual) #We need to create a family here of both partners if profile_obtained.gen_data["gender"] == "M": new_gedcom.create_family(profile_temp, partner, []) else: new_gedcom.create_family(partner, profile_temp, []) if id_of_marriage in self.parents_profiles.keys(): father = self.parents_profiles[id_of_marriage][0] mother = self.parents_profiles[id_of_marriage][1] #We now convert the profiles into the profile gedcom_profile.convert_gedcom(father) gedcom_profile.convert_gedcom(mother) #We add them to the file new_gedcom.add_element(father.individual) new_gedcom.add_element(mother.individual) #And the family!!! new_gedcom.create_family(father, mother, [partner]) #We create here the family new_gedcom.create_family(self.father_profile, self.mother_profile, children_ged) new_gedcom.save(output)
def introduce_family(self, init_profile, gedcom_db): ''' Recursive function to introduce the family in the gedcom database ''' logging.info(NUMBER_OF_PROFILES + str(len(self.added_profiles.keys())) + PROCESSING + init_profile.nameLifespan()) #Let's take first the children children = init_profile.children prof_id = init_profile.geni_specific_data["id"] #For the first profile we check first if the profile has been generated first if not isinstance(init_profile, gedcom_profile): #Notice that we will only go through this one a single time, as all the others #will be generated in the next step gedcom_profile.convert_gedcom(init_profile) gedcom_db.add_profile(init_profile) self.added_profiles[prof_id] = init_profile #Firstly we will create the array with all the partners in it and also with their ids in the database children_matrix = {} children_ids = {} for id_partner in init_profile.partner: children_matrix[id_partner] = [] children_ids[id_partner] = [] for new_id in children: #First thing to check is if we have already added the profile, we might #be in the situation of double profiles in intermarriage of descendants. new_prof = None if not (new_id in self.added_profiles.keys()): #Ok, if really a new profile, so we create it, we transfor it and #also we add to the added profiles new_prof = profile.profile(new_id) gedcom_profile.convert_gedcom(new_prof) gedcom_db.add_profile(new_prof) self.added_profiles[new_id] = new_prof #And we investigate, obviously! self.introduce_family(new_prof, gedcom_db) else: new_prof = self.added_profiles[new_id] #To avoid removing data from the profile we create a temp array using #the method list to avoid a linked copy temp_parents = list(new_prof.parents) #When not having access to a profile in geni, the parents provided are empty if prof_id in temp_parents: temp_parents.remove(prof_id) #Notice that we might have the situation of a single parent! if (len(temp_parents) > 0): #Let's find the profile which is already included. correct_parent = None if temp_parents[0] in children_matrix.keys(): correct_parent = temp_parents[0] else: correct_parent = temp_parents[1] children_matrix[correct_parent].append(new_prof) children_ids[correct_parent].append(new_prof.get_id()) #Only in case there is a partner, we include him/her! if (len(init_profile.partner) > 0): #Now let's use the partner as well, we may have several partners for id_partner in children_matrix.keys(): prof_partner = None #First thing, we need to check the partner is already identified or not if (id_partner in self.added_profiles.keys()): #We take the previous so! prof_partner = self.added_profiles[id_partner] else: #We get the profile data prof_partner = profile.profile(id_partner) #We add the profile in! gedcom_profile.convert_gedcom(prof_partner) #Now goes to the gedcom gedcom_db.add_profile(prof_partner) #And we mark is already in added profiles self.added_profiles[id_partner] = prof_partner #We create here the family gedcom_db.add_family(father=init_profile.get_id(), mother=prof_partner.get_id(), children=children_ids[id_partner])
def create_gedcom_file(self, output): ''' This function will create the gedcom file that can be read by other genealogical tools ''' if not self.correct_execution: logging.error(NO_GENI_EXECUTION) return False else: #We create first the database, a Gedcom one dbged = db_gedcom() #We make father and mother a gedcom_profile gedcom_profile.convert_gedcom(self.father_profile) gedcom_profile.convert_gedcom(self.mother_profile) #We add now the father and mother to the database id_father = dbged.add_profile(self.father_profile) id_mother = dbged.add_profile(self.mother_profile) #We prepare the children adding children_ged = [] for profile_obtained in self.profiles: #We convert each profile into the gedcom profile profile_temp = profile_obtained gedcom_profile.convert_gedcom(profile_temp) id_child = dbged.add_profile(profile_temp) children_ged.append(id_child) if profile_obtained.gen_data.get( "marriage_link", None) in self.related_profiles.keys(): id_of_marriage = profile_obtained.gen_data["marriage_link"] #We capture the partner partner = self.related_profiles[id_of_marriage] gedcom_profile.convert_gedcom(partner) #We add the partner id_partner = dbged.add_profile(partner) #We need to create a family here of both partners if profile_obtained.gen_data["gender"] == "M": dbged.add_family(father=id_child, mother=id_partner) else: dbged.add_family(father=id_partner, mother=id_child) if id_of_marriage in self.parents_profiles.keys(): father = self.parents_profiles[id_of_marriage][0] mother = self.parents_profiles[id_of_marriage][1] #We now convert the profiles into the profile gedcom_profile.convert_gedcom(father) gedcom_profile.convert_gedcom(mother) #We add them to the file id_partner_father = dbged.add_profile(father) id_partner_mother = dbged.add_profile(mother) #And the family!!! dbged.add_family(father=id_partner_father, mother=id_partner_mother, children=[id_partner]) #We create here the family dbged.add_family(father=id_father, mother=id_mother, children=children_ged) dbged.save_gedcom_file(output)
''' Created on 16 oct. 2017 @author: Val This example creates a profile, converts into GEDCOM format and builds it ''' from pyGenealogy.common_profile import gen_profile from pyGedcom.gedcom_profile import gedcom_profile from pyGedcom.gedcompy_wrapper import gedcom_file #Standard creation of a profile profile = gen_profile("John", "Smith") #Profile is converted into a profile prepared for gedcom gedcom_profile.convert_gedcom(profile) #We create the new gedcom file and we add the new profile new_gedcom = gedcom_file() new_gedcom.add_element(profile.individual) #If you want to save the file... new_gedcom.save("myoutput.ged")