Ejemplo n.º 1
0
 def create_as_a_child(cls,
                       base_profile,
                       union=None,
                       profile=None,
                       geni_input=None,
                       type_geni="g"):
     '''
     From a common profile from pyGenealogy library, a new profile will be created
     as a child of a given union of 2 profiles.
     '''
     union_to_use = None
     if (union != None):
         union_to_use = union
     elif (profile != None):
         if (len(profile.marriage_union) == 1):
             union_to_use = profile.marriage_union[0].union_id
     elif (geni_input != None):
         tmp_prof = cls.create_internally(geni_input, type_geni)
         #TODO: add error checking if tmp_prof is not properly created.
         if (len(tmp_prof.marriage_union) == 1):
             union_to_use = tmp_prof.marriage_union[0].union_id
         else:
             #We have a problem, potentially a wrong profile
             logging.error(NO_VALID_UNION_PROFILE +
                           str(len(tmp_prof.marriage_union)))
     if (union_to_use == None): return False
     #Calling essentially the constructors
     base_profile.__class__ = cls
     geni_calls.__init__(cls)
     #We create the url for creating the child
     add_child = s.GENI_API + union_to_use + s.GENI_ADD_CHILD + s.GENI_INITIATE_PARAMETER + "first_name="
     add_child += base_profile.gen_data[
         "name"] + s.GENI_ADD_PARAMETER + s.GENI_TOKEN + s.get_token()
     base_profile.creation_operations(add_child)
     return True
Ejemplo n.º 2
0
 def __init__(self, union_id):
     '''
     Constructor
     '''
     #We initiate the base classes
     geni_calls.__init__(self)
     url = geni.GENI_API + union_id + geni.GENI_SINGLE_TOKEN + geni.get_token(
     )
     r = geni.geni_request_get(url)
     data = r.json()
     self.union_data = {}
     for key_value in data.keys():
         if key_value == "id": self.union_data["id"] = data[key_value]
         if key_value == "url": self.union_data["url"] = data[key_value]
         if key_value == "guid": self.union_data["guid"] = data[key_value]
         if key_value == "marriage_date":
             day = data["marriage_date"].get("day", 1)
             month = data["marriage_date"].get("month", 1)
             year = data["marriage_date"].get("year", 1)
             self.union_data["marriage_date"] = date(year, month, day)
         if key_value == "marriage_location":
             self.union_data["marriage_place"] = {}
             for location_key in data["marriage_location"].keys():
                 if location_key == "city":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "county":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "state":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "country":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "country_code":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "latitude":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "longitude":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
                 if location_key == "formatted_location":
                     self.union_data["marriage_place"][location_key] = data[
                         "marriage_location"][location_key]
         if key_value == "status":
             self.union_data["status"] = data[key_value]
         if key_value == "partners":
             self.union_data["partners"] = data[key_value]
         if key_value == "children":
             self.union_data["children"] = data[key_value]
    def check_valid_genikey(self):
        # Validate access token, connecting to Geni, this might take a while
        valid_token = s.geni_request_get(s.GENI_VALIDATE_TOKEN + str(s.get_token())).json()

        tokenIsOk = False
        #The way the API informs of a wrong token is the following:
        #{'error': 'invalid_token', 'error_description': 'invalid token'}
        if ('error' in valid_token):
            #We got an error, we shall notify!
            logging.error(NO_VALID_TOKEN)
        elif ( str(valid_token['result']) == "OK"):
            tokenIsOk = True
        return tokenIsOk
Ejemplo n.º 4
0
 def create_as_a_partner(cls,
                         base_profile,
                         profile=None,
                         geni_input=None,
                         type_geni="g"):
     '''
     From a common profile we take another profile and we create at parnter.
     '''
     partner_to_use = process_profile_input(profile, geni_input, type_geni)
     #Calling essentially the constructors
     base_profile.__class__ = cls
     geni_calls.__init__(cls)
     #We create the url for creating the child
     add_partner = partner_to_use + s.GENI_ADD_PARTNER + s.GENI_INITIATE_PARAMETER + "first_name="
     add_partner += base_profile.gen_data[
         "name"] + s.GENI_ADD_PARAMETER + s.GENI_TOKEN + s.get_token()
     base_profile.creation_operations(add_partner)
     base_profile.add_marriage_in_geni()
Ejemplo n.º 5
0
 def create_as_a_child(cls,
                       base_profile,
                       union=None,
                       profile=None,
                       geni_input=None,
                       type_geni="g",
                       only_one_parent=False):
     '''
     From a common profile from pyGenealogy library, a new profile will be created
     as a child of a given union of 2 profiles.
     union the union it will be added
     proile the geni profile
     geni_input the inptu fro geni if avaialbel
     only_one_parent is used when there is a sinlge parent
     '''
     union_to_use = None
     if (union is not None):
         union_to_use = union
     elif (profile is not None):
         if (len(profile.marriage_union) == 1) and not only_one_parent:
             union_to_use = profile.marriage_union[0].union_id
     elif (geni_input is not None):
         tmp_prof = cls.create_internally(geni_input, type_geni)
         #TODO: add error checking if tmp_prof is not properly created.
         if (len(tmp_prof.marriage_union) == 1):
             union_to_use = tmp_prof.marriage_union[0].union_id
         else:
             #We have a problem, potentially a wrong profile
             logging.error(NO_VALID_UNION_PROFILE +
                           str(len(tmp_prof.marriage_union)))
     #Calling essentially the constructors
     data_input = create_input_file_2_geni(base_profile)
     base_profile.__class__ = cls
     geni_calls.__init__(cls)
     #We create the url for creating the child
     if (union_to_use is None):
         add_child = s.GENI_API + profile.get_id()
     else:
         add_child = s.GENI_API + union_to_use
     add_child += s.GENI_ADD_CHILD + s.GENI_INITIATE_PARAMETER + "first_name=" + base_profile.gen_data[
         "name"] + s.GENI_ADD_PARAMETER + s.GENI_TOKEN + s.get_token()
     base_profile.creation_operations(add_child, data_input)
     return True
Ejemplo n.º 6
0
 def __init__(self, union_id):
     '''
     Constructor it takes the union id from Geni
     '''
     #We initiate the base classes
     geni_calls.__init__(self)
     family_profile.__init__(self)
     data = ""
     if (union_id in geni.GENI_CALLED_UNIONS):
         #In order to save calls we try to save the different calls
         data = geni.GENI_CALLED_UNIONS[union_id]
     else:
         url = geni.GENI_API + union_id + geni.GENI_SINGLE_TOKEN + geni.get_token(
         )
         r = geni.geni_request_get(url)
         data = r.json()
         geni.GENI_CALLED_UNIONS[union_id] = data
     self.union_data = {}
     #Initiating values of the parametrs
     self.union_data["partners"] = []
     for key_value in data.keys():
         if key_value == "id": self.union_data["id"] = data[key_value]
         if key_value == "url": self.union_data["url"] = data[key_value]
         if key_value == "guid": self.union_data["guid"] = data[key_value]
         if key_value == "marriage_date":
             #We might have an existing marriage in the file
             self.union_data["marriage"] = self.get_date(
                 "marriage",
                 data["marriage_date"],
                 previous_event=self.union_data.get("marriage", None))
         if key_value == "marriage_location":
             place_data = {}
             for location_key in data["marriage_location"].keys():
                 if location_key == "city":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "county":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "state":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country_code":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "latitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "longitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "formatted_location":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
             if not ("marriage" in self.union_data.keys()):
                 self.union_data["marriage"] = event_profile("marriage")
             self.union_data["marriage"].setLocationAlreadyProcessed(
                 place_data)
         if key_value == "status":
             self.union_data["status"] = data[key_value]
         if key_value == "partners":
             #The union stores the partner as a full address, but we are looking for the profile ID which is stored
             for partner in data[key_value]:
                 self.union_data["partners"].append(partner.split("/")[-1])
             self.setFather(
                 geni.get_profile_id_from_address(data[key_value][0]))
             if len(data.get(key_value, None)) > 1:
                 self.setMother(
                     geni.get_profile_id_from_address(data[key_value][1]))
         if key_value == "children":
             self.union_data["children"] = data[key_value]
             children = []
             for child in data[key_value]:
                 children.append(geni.get_profile_id_from_address(child))
             self.setChild(children)
Ejemplo n.º 7
0
 def create_as_a_parent(cls,
                        base_profile,
                        profile=None,
                        geni_input=None,
                        type_geni="g"):
     '''
     From a common profile from pyGenealogy library, a new profile will be created
     as a parent of a given profile
     '''
     child_to_use = process_profile_input(profile, geni_input, type_geni)
     #Calling essentially the constructors
     base_profile.__class__ = cls
     geni_calls.__init__(cls)
     #We create the url for creating the child
     add_parent = child_to_use + s.GENI_ADD_PARENT + s.GENI_INITIATE_PARAMETER + s.GENI_TOKEN + s.get_token(
     )
     #We also add the needed data, that we take from the base profile directly
     base_profile.creation_operations(add_parent)
Ejemplo n.º 8
0
 def add_marriage_in_geni(self, union=None):
     '''
     This method add marriage data in geni, add union if there is no unique
     marriage
     '''
     if (union == None):
         #If no union is added is because is the unique...
         if (len(self.marriage_union) == 1):
             union = self.marriage_union[0].union_id
         else:
             #If we have more than one marriage we cannot proceed
             return False
     #We create the url for creating the child
     update_marriage = s.GENI_API + union + s.GENI_UPDATE + s.GENI_INITIATE_PARAMETER + s.GENI_TOKEN + s.get_token(
     )
     #We add the event data for marriage
     data_input = {}
     event_value = self.event_value("marriage")
     if (event_value): data_input["marriage"] = event_value
     #We also add the needed data, that we take from the base profile directly
     r = s.geni_request_post(update_marriage, data_input=data_input)
     data = r.json()
     if "error" in data.keys():
         logging.error(ERROR_REQUESTS + data["error"])
Ejemplo n.º 9
0
 def token_string(self):
     return s.GENI_SINGLE_TOKEN + s.get_token()
Ejemplo n.º 10
0
 def __init__(self, union_id):
     '''
     Constructor it takes the union id from Geni
     '''
     #We initiate the base classes
     geni_calls.__init__(self)
     data = ""
     if (union_id in geni.GENI_CALLED_UNIONS):
         #In order to save calls we try to save the different calls
         data = geni.GENI_CALLED_UNIONS[union_id]
     else:
         url = geni.GENI_API + union_id + geni.GENI_SINGLE_TOKEN + geni.get_token(
         )
         r = geni.geni_request_get(url)
         data = r.json()
         geni.GENI_CALLED_UNIONS[union_id] = data
     self.union_data = {}
     for key_value in data.keys():
         if key_value == "id": self.union_data["id"] = data[key_value]
         if key_value == "url": self.union_data["url"] = data[key_value]
         if key_value == "guid": self.union_data["guid"] = data[key_value]
         if key_value == "marriage_date":
             #We might have an existing marriage in the file
             self.union_data["marriage"] = self.get_date(
                 "marriage",
                 data["marriage_date"],
                 previous_event=self.union_data.get("marriage", None))
         if key_value == "marriage_location":
             place_data = {}
             for location_key in data["marriage_location"].keys():
                 if location_key == "city":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "county":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "state":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "country_code":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "latitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "longitude":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
                 if location_key == "formatted_location":
                     place_data[location_key] = data["marriage_location"][
                         location_key]
             if not ("marriage" in self.union_data.keys()):
                 self.union_data["marriage"] = event_profile("marriage")
             self.union_data["marriage"].setLocationAlreadyProcessed(
                 place_data)
         if key_value == "status":
             self.union_data["status"] = data[key_value]
         if key_value == "partners":
             self.union_data["partners"] = data[key_value]
         if key_value == "children":
             self.union_data["children"] = data[key_value]