From 61d7aa7298e9a941337ae98e3039fba63224d491 Mon Sep 17 00:00:00 2001 From: Norm Rasmussen Date: Wed, 5 Apr 2023 18:49:34 -0400 Subject: [PATCH] Finished mizuno script. Changed Walmart's courses script. Added some notes. --- Scripts/API_Tests/add-pgaids.py | 63 +++++++++++++++++++++++++++++++ Scripts/API_Tests/add_prop_csv.py | 1 - Scripts/API_Tests/get_courses.py | 3 +- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 Scripts/API_Tests/add-pgaids.py diff --git a/Scripts/API_Tests/add-pgaids.py b/Scripts/API_Tests/add-pgaids.py new file mode 100644 index 00000000..147badce --- /dev/null +++ b/Scripts/API_Tests/add-pgaids.py @@ -0,0 +1,63 @@ +import requests +import pandas as pd +from pathlib import Path +import Apikeys +import os + +basefile = "/Users/normrasmussen/Downloads/mizuno-monthly-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] + url = uuid_url + f"{email}" + response = requests.get(url, headers=headers) + if response.status_code == 200: + response = response.json() + print(response) + uuid = response["data"][0]["id"] + print(uuid) + url2 = prop_url + f"{uuid}" + response = requests.get(url2, headers=headers) + data = response.json() + pgaid = data["data"]["attributes"]["properties"]["account_number"] + row_dict["pgaid"] = pgaid + elif response.status_code == 404: + row_dict["pgaid"] = "User Not Found" + dict_list.append(row_dict) + print("No errors! Passing along the dictionary!") + except KeyError as e: + print(e) + finally: + for info in dict_list: + row = info['row_num'] + pid = info['pgaid'] + completions.loc[completions.index[row], "PGA ID"] = pid + completions = completions[completions["PGA ID"] != "0"] + #completions = completions.iloc[:, 0:] + print(completions) + completions.to_csv( + "/Users/normrasmussen/Downloads/MizunoCompletions_with_PGAIDs.csv", + index=False + ) + + +if __name__ == "__main__": + load_file(basefile) + diff --git a/Scripts/API_Tests/add_prop_csv.py b/Scripts/API_Tests/add_prop_csv.py index d79fe7a1..de77a12d 100644 --- a/Scripts/API_Tests/add_prop_csv.py +++ b/Scripts/API_Tests/add_prop_csv.py @@ -1,4 +1,3 @@ - import requests import pandas as pd from pathlib import Path diff --git a/Scripts/API_Tests/get_courses.py b/Scripts/API_Tests/get_courses.py index a0c23430..609f5816 100644 --- a/Scripts/API_Tests/get_courses.py +++ b/Scripts/API_Tests/get_courses.py @@ -13,6 +13,7 @@ def get_course(): while True: count += 1 url = f"https://api2.northpass.com/v2/courses?page={count}" + print(url) headers = {"accept": "application/json", "X-Api-Key": apiKey} response = requests.get(url, headers=headers) data = response.json() @@ -33,7 +34,7 @@ def get_course(): # FIX: After this, something is being overwritten. cat_id = response["relationships"]["categories"]["data"] - get_cat_name(cat_id, course_dict, courses) + # get_cat_name(cat_id, course_dict, courses) if "next" not in nextlink: break