Files
Gainsight/Scripts/Mizuno/add-pgaids.py
2023-04-03 17:16:01 -04:00

59 lines
1.8 KiB
Python

import requests
import pandas as pd
from pathlib import Path
import os
basefile = "/Users/normrasmussen/Downloads/mizuno-march-completions.csv"
api_key = "stXNF84HWL8aCGeRjHEo2rJ1U"
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",
}
drop_rows = []
def load_file(basefile):
try:
if os.path.isfile(basefile):
basefile = Path(basefile)
print(f"File found! Importing {basefile}")
completions = pd.read_csv(basefile)
for email in completions.itertuples():
row_num = email[0]
email = email[3]
print(email)
url = uuid_url + f"{email}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
print("Fetching person found!")
response = response.json()
uuid = response["data"][0]["id"]
url2 = prop_url + f"{uuid}"
response = requests.get(url2, headers=headers)
data = response.json()
pgaid = data["data"]["attributes"]["properties"]["account_number"]
write_to_csv(pgaid, row_num, completions)
except KeyError as e:
print(e)
finally:
pass
def write_to_csv(pgaid, row_num, completions):
print(pgaid)
try:
completions.loc[completions.index[row_num], "PGA ID"] = pgaid
except (TypeError, KeyError) as e:
print(e)
finally:
pass
#completions.drop(completions["PGA ID"] == "0")
print("the end?")
print(completions)
if __name__ == "__main__":
load_file(basefile)