Api keys, course scripts for Spark. Todos.

This commit is contained in:
Norm Rasmussen
2024-12-19 15:57:45 -05:00
parent 123676993a
commit c1d4234407
5 changed files with 29 additions and 43 deletions

View File

@ -32,3 +32,4 @@ BLOOMERANG = "ewGDqLgsklMnytqzUka2wmgIi"
GSU = "rUUKNuBZ0rmRNPftB4smYhQ5L" GSU = "rUUKNuBZ0rmRNPftB4smYhQ5L"
EMPLOY = "qcNggCm4SBtC0gTqLGv30vX8l" EMPLOY = "qcNggCm4SBtC0gTqLGv30vX8l"
LUMAFINTECH = "oDFA7XSmjEKjEwIDIKLm0rxs1" LUMAFINTECH = "oDFA7XSmjEKjEwIDIKLm0rxs1"
SUPPLIERPROD = "DtRH9m4r0zMbJEx1yWBGKlObi"

View File

@ -4,25 +4,16 @@ import Apikeys
import pprint import pprint
pp = pprint.PrettyPrinter(indent=4) pp = pprint.PrettyPrinter(indent=4)
apiKey = Apikeys.SKUID apiKey = Apikeys.SUPPLIERPROD
course_dict = {} course_dict = {}
COURSES= [
"Shopping an order",
"Delivery FAQs",
"Checking out Shopping & Delivery orders",
"Shopping & Delivery FAQs",
"Communicating with customers",
"Delivering an order",
]
def get_course(): def get_course():
count = 0 count = 0
courses = [] courses = []
while True: while True:
count += 1 count += 1
url = f"https://api.northpass.com/v2/courses?page={count}" url = f"https://api2.northpass.com/v2/courses?page={count}"
headers = {"accept": "application/json", "X-Api-Key": apiKey} headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
data = response.json() data = response.json()
@ -32,9 +23,6 @@ def get_course():
status = response["attributes"]["status"] status = response["attributes"]["status"]
uuid = response["id"] uuid = response["id"]
name = response["attributes"]["name"] name = response["attributes"]["name"]
# build_url = response["links"]["builder"]["href"]
# if name in COURSES:
print(uuid)
course_dict = { course_dict = {
"id": uuid, "id": uuid,
"name": name, "name": name,
@ -43,7 +31,6 @@ def get_course():
# "url": f"https://walmart.northpass.com/app/courses/{uuid}", # "url": f"https://walmart.northpass.com/app/courses/{uuid}",
} }
courses.append(course_dict) courses.append(course_dict)
# print(courses)
# FIX: Up until here, each course gets read to the terminal. # FIX: Up until here, each course gets read to the terminal.
# FIX: After this, something is being overwritten. # FIX: After this, something is being overwritten.
@ -54,49 +41,41 @@ def get_course():
if "next" not in nextlink: if "next" not in nextlink:
break break
# write_to_csv(courses)
# pp.pprint(courses)
# print(len(courses))
def get_cat_name(cat_id, course_dict, courses): def get_cat_name(cat_id, course_dict, courses):
headers = {"accept": "application/json", "X-Api-Key": apiKey} headers = {"accept": "application/json", "X-Api-Key": apiKey}
cats = []
if len(cat_id) == 0: if len(cat_id) == 0:
pass pass
elif len(cat_id) == 1: # elif len(cat_id) == 1:
categoryid = cat_id[0]["id"] # categoryid = cat_id[0]["id"]
url = f"https://api.northpass.com/v2/categories/{categoryid}" # url = f"https://api2.northpass.com/v2/categories/{categoryid}"
cat_resp = requests.get(url, headers=headers) # cat_resp = requests.get(url, headers=headers)
cat_data = cat_resp.json() # cat_data = cat_resp.json()
try: # try:
cat_name = cat_data["data"]["attributes"]["name"] # cat_name = cat_data["data"]["attributes"]["name"]
cats.append(cat_name) # cats.append(cat_name)
course_dict.update({"categories": cats}) # course_dict.update({"categories": cats})
except KeyError: # except KeyError:
print(f"key error for cat {cat_id}") # print(f"key error for cat {cat_id}")
finally: # finally:
pass # pass
else: else:
cats = []
for item in cat_id: for item in cat_id:
categoryid = item["id"] categoryid = item["id"]
url = f"https://api.northpass.com/v2/categories/{categoryid}" url = f"https://api2.northpass.com/v2/categories/{categoryid}"
cat_resp = requests.get(url, headers=headers) cat_resp = requests.get(url, headers=headers)
cat_data = cat_resp.json() cat_data = cat_resp.json()
cat_name = cat_data["data"]["attributes"]["name"] cat_name = cat_data["data"]["attributes"]["name"]
cats.append(cat_name) cats.append(cat_name)
course_dict.update({"categories": cats}) course_dict.update({"categories": cats})
print(course_dict)
try: write_to_csv(courses)
courses.append(course_dict)
except TypeError as e:
print(f"Error: {e}")
finally:
write_to_csv(courses)
def write_to_csv(courses): def write_to_csv(courses):
df = pd.DataFrame.from_dict(courses) df = pd.DataFrame.from_dict(courses)
df.to_csv("/Users/normrasmussen/Downloads/sps_courses.csv") df.to_csv("/Users/normrasmussen/Downloads/supplier_courses.csv")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -7,7 +7,7 @@ import requests
import pandas as pd import pandas as pd
import Apikeys import Apikeys
APIKEY = Apikeys.SPARKPROD APIKEY = Apikeys.SUPPLIERPROD
COURSES = [] COURSES = []
HEADERS = {"accept": "application/json", "X-Api-Key": APIKEY} HEADERS = {"accept": "application/json", "X-Api-Key": APIKEY}

View File

@ -454,3 +454,9 @@ New Commerce Catalog:
* Issue is that this needs to be addressed with supplier. * Issue is that this needs to be addressed with supplier.
## 12/19/2024
- [ ] Walmart - See if we can get when Jess added courses to the LP in Spark
- [X] Walmart - PDF of LP overview screens
- [X] Walmart - CSV of LPs and their Courses
- [ ] Chubb - Revisit Qualtrics Milestone