Пример #1
0
 def __init__(self,
              geni_input,
              type_geni="g",
              data_language="en",
              data_value=None):
     '''
     The geni input provided can be:
     - The id of the profile
     - The id of the profile with g
     - Each address of the profile.
     - data_value: is the raw output from Geni API that can be used for direct data introductions
     '''
     #Some checking parameters initiated
     self.properly_executed = False
     self.existing_in_geni = False
     self.merged_in_geni = False
     self.geni_specific_data = {}
     #We initiate the base classes
     geni_calls.__init__(self)
     #It is possible to introduce the direct raw data from geni to the profile
     if data_value: data = data_value
     else:
         url = process_geni_input(geni_input,
                                  type_geni) + self.token_string()
         r = s.geni_request_get(url)
         data = r.json()
     #In case the profile has been merged to other profile, as the information is available it will be modified.
     if (data.get("merged_into", None) and data.get("deleted", None)):
         self.merged_in_geni = True
         url = data.get("merged_into") + self.token_string()
         r = s.geni_request_get(url)
         data = r.json()
     #Now we can execute the constructor
     if ("first_name" not in data.keys()):
         data["first_name"] = NOT_KNOWN_VALUE
     if ("last_name" not in data.keys()):
         data["last_name"] = data.get("maiden_name", NOT_KNOWN_VALUE)
     gen_profile.__init__(self,
                          data["first_name"],
                          data["last_name"],
                          id_db=data.get("id", None),
                          data_language="en")
     #In some cases we do not have access to the profile and data is not accurate
     if data.get("name", None):
         if ("<private>" in data["name"]): self.set_accessible(False)
     if not "error" in data.keys():
         self.existing_in_geni = True
         self.fulldata = data
         if "mugshot_urls" in data:
             data.pop("mugshot_urls")
         if "photo_urls" in data:
             data.pop("photo_urls")
         self.data = data
         self.get_geni_data(data)
         self.properly_executed = True
Пример #2
0
 def get_several_profile_by_ID(self, ID_array):
     '''
     Returns a dict of profiles from Geni
     ID_array is a list of profile IDs.
     '''
     input_array = ""
     if (len(ID_array) ==1): return {ID_array[0] : self.get_profile_by_ID(ID_array[0])}
     #This variable is used to check the case all profiles are already available to avoid a call
     all_profiles_existing = True
     for id_one in ID_array:
         if id_one not in self.profiles.keys(): all_profiles_existing = False
         input_array = input_array + "," + id_one
     #We have 2 options, if all profiles are existing in the interface, we do not need to do the call...
     output_array = {}
     if all_profiles_existing:
         for id_one in ID_array:
             output_array[id_one] = self.get_profile_by_ID(id_one)
     else:
         #There is a bug in the API, apparently is not working....
         DUMMY_INPUT = "profile-1"
         url = s.GENI_PLUS_PROFILES + input_array[1:]+ "," + DUMMY_INPUT + self.token_string()
         r = s.geni_request_get(url)
         data = r.json()
         for prof_data in data["results"]:
             if not ( prof_data["id"] == DUMMY_INPUT):
                 output_array[prof_data["id"]] = profile(prof_data["id"], prof_data)
     return output_array
Пример #3
0
 def __init__(self, geni_input, type_geni="g"):  # id int or string
     '''
     The geni input provided can be:
     - The id of the profile
     - The id of the profile with g
     - Each address of the profile.
     '''
     #Some checking parameters initiated
     self.properly_executed = False
     self.existing_in_geni = False
     self.geni_specific_data = {}
     #We initiate the base classes
     geni_calls.__init__(self)
     url = process_geni_input(geni_input, type_geni) + self.token_string()
     r = s.geni_request_get(url)
     data = r.json()
     #Now we can execute the constructor
     if (not "first_name" in data.keys()):
         data["first_name"] = NOT_KNOWN_VALUE
     if (not "last_name" in data.keys()):
         data["last_name"] = NOT_KNOWN_VALUE
     gen_profile.__init__(self,
                          data["first_name"],
                          data["last_name"],
                          id_db=data.get("id", None))
     if not "error" in data.keys():
         self.existing_in_geni = True
         self.fulldata = data
         if "mugshot_urls" in data:
             data.pop("mugshot_urls")
         if "photo_urls" in data:
             data.pop("photo_urls")
         self.data = data
         self.get_geni_data(data)
         self.properly_executed = True
Пример #4
0
 def test_error_get_post(self):
     '''
     Test error get and post
     '''
     data = geni_request_get(GENI_WRONG_GET_METHOD)
     assert ("error" in data.json())
     data2 = geni_request_post(GENI_WRONG_GET_METHOD)
     assert ("error" in data2.json())
Пример #5
0
 def __init__(self, myid):
     '''
     The constructor will also make the call to the web to get the right
     string
     '''
     input_id = myid
     #This will allow to intoduce the complete direction of the profile
     if "https" in myid:
         input_id = "profile" + myid.split("profile")[1]
     #Initiating base class
     geni_calls.__init__(self)
     self.union_url = self.get_profile_url(
         input_id) + s.GENI_FAMILY + self.token_string()
     r = s.geni_request_get(self.union_url)
     self.data = r.json()
     #we initialize the lists
     self.error = False
     self.union_extracted = False
     self.parents = []
     self.sibligns = []
     self.partner = []
     self.children = []
     self.parent_union = []
     self.marriage_union = []
     self.marriage_events = []
     if not ('error' in self.data):
         #In this case, we have extracted properly the union data
         self.union_extracted = True
         #the nodes include the data of the different affected profiles and unions
         for keydata in self.data["nodes"].keys():
             #is easier to go to the usions, so we filter by unions.
             if "union" in keydata:
                 #Good... let's obtain the data from the union
                 tmp_union = geni_union(self.data["nodes"][keydata],
                                        keydata)
                 #Now we need to filter the parents and children as we should not duplicate
                 if tmp_union.is_profile_child(input_id):
                     #We know is a child... so
                     self.parents = self.parents + tmp_union.parents
                     tmp_union.children.remove(input_id)
                     self.sibligns = self.sibligns + tmp_union.children
                     self.parent_union.append(tmp_union)
                 else:
                     #In this case we know is a marriage union
                     tmp_union.parents.remove(input_id)
                     self.partner = self.partner + tmp_union.parents
                     self.children = self.children + tmp_union.children
                     #We obtain the union from Geni in order to introduce the marriage
                     marriage_union = union(tmp_union.union_id)
                     self.marriage_union.append(tmp_union)
                     if "marriage" in marriage_union.union_data.keys():
                         self.marriage_events.append(
                             marriage_union.union_data.get(
                                 'marriage', None))
     else:
         self.error = True
Пример #6
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
 def __init__(self, myid):
     '''
     The constructor will also make the call to the web to get the right
     string
     '''
     #Initiating base class
     geni_calls.__init__(self)
     self.union_url = self.get_profile_url(
         myid) + s.GENI_FAMILY + self.token_string()
     r = s.geni_request_get(self.union_url)
     self.data = r.json()
     #we initialize the lists
     self.union_extracted = False
     self.parents = []
     self.sibligns = []
     self.partner = []
     self.children = []
     self.parent_union = []
     self.marriage_union = []
     if not ('error' in self.data):
         #In this case, we have extracted properly the union data
         self.union_extracted = True
         #the nodes include the data of the different affected profiles and unions
         for keydata in self.data["nodes"].keys():
             #is easier to go to the usions, so we filter by unions.
             if "union" in keydata:
                 #Good... let's obtain the data from the union
                 tmp_union = geni_union(self.data["nodes"][keydata],
                                        keydata)
                 #Now we need to filter the parents and children as we should not duplicate
                 if tmp_union.is_profile_child(myid):
                     #We know is a child... so
                     self.parents = self.parents + tmp_union.parents
                     tmp_union.children.remove(myid)
                     self.sibligns = self.sibligns + tmp_union.children
                     self.parent_union.append(tmp_union)
                 else:
                     tmp_union.parents.remove(myid)
                     self.partner = self.partner + tmp_union.parents
                     self.children = self.children + tmp_union.children
                     self.marriage_union.append(tmp_union)
Пример #9
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)
Пример #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]