61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
import requests
|
|
import pandas as pd
|
|
from pathlib import Path
|
|
import Apikeys
|
|
import os
|
|
|
|
basefile = "/Users/normrasmussen/Downloads/mizuno-oct-completions.csv"
|
|
api_key = Apikeys.MIZUNO
|
|
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
|
|
prop_url = "https://api.northpass.com/v2/properties/people/"
|
|
headers = {
|
|
"accept": "*/*",
|
|
"x-api-key": api_key,
|
|
"content-type": "application/json",
|
|
}
|
|
|
|
|
|
def load_file(basefile):
|
|
dict_list = []
|
|
row_dict = {}
|
|
basefile = Path(basefile)
|
|
completions = pd.read_csv(basefile)
|
|
try:
|
|
if os.path.isfile(basefile):
|
|
print(f"File found! Importing {basefile}")
|
|
for email in completions.itertuples():
|
|
row_num = email[0]
|
|
row_dict = {"row_num": row_num}
|
|
email = email[3]
|
|
print(email)
|
|
url = uuid_url + f"{email}"
|
|
response = requests.get(url, headers=headers)
|
|
if response.status_code == 200:
|
|
response = response.json()
|
|
uuid = response["data"][0]["id"]
|
|
url2 = prop_url + f"{uuid}"
|
|
response = requests.get(url2, headers=headers)
|
|
data = response.json()
|
|
userid = data["data"]["attributes"]["properties"]["account_number"]
|
|
row_dict["userid"] = userid
|
|
dict_list.append(row_dict)
|
|
print("No errors! Passing along the dictionary!")
|
|
except KeyError as e:
|
|
print(f"{e} and the rest")
|
|
finally:
|
|
for info in dict_list:
|
|
row = info["row_num"]
|
|
pid = info["userid"]
|
|
print(f"PID IS {pid}")
|
|
completions.loc[completions.index[row], "userid"] = pid
|
|
completions = completions[completions["userid"] != "0"]
|
|
# completions = completions.iloc[:, 0:]
|
|
completions.to_csv(
|
|
"/Users/normrasmussen/Downloads/Mizuno-Oct2024-with-PGAID.csv",
|
|
index=False,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
load_file(basefile)
|