diff --git a/Scripts/API_Tests/get_courses_and_associated_groupscategories.py b/Scripts/API_Tests/get_courses_and_associated_groupscategories.py new file mode 100644 index 00000000..a9778969 --- /dev/null +++ b/Scripts/API_Tests/get_courses_and_associated_groupscategories.py @@ -0,0 +1,121 @@ +import requests +from collections import Counter +import pandas as pd +import Apikeys +import pprint + +pp = pprint.PrettyPrinter(indent=4) +apiKey = Apikeys.SUPPLIERPROD +course_dict = {} +HEADERS = {"accept": "application/json", "X-Api-Key": apiKey} + +def get_groups(): + grouple = [] + count = 0 + + while True: + count += 1 + url = f"https://api2.northpass.com/v2/groups?page={count}" + gresponse = requests.get(url, headers=HEADERS).json() + nextlink = gresponse["links"] + + for gresp in gresponse["data"]: + grouple.append(( gresp["id"], gresp["attributes"]["name"] )) + + if "next" not in nextlink: + break + + return grouple + +def compare_groups(course_uuid): + compcount = 0 + complist = [] + + while True: + compcount += 1 + # Endpoint is for list groups not yet associated with course + compareurl = f"https://api2.northpass.com/v2/courses/{course_uuid}/available_groups?page={compcount}" + comparedata = requests.get(compareurl, headers=HEADERS).json() + nextlink = comparedata["links"] + + for cresp in comparedata["data"]: + complist.append(( cresp["id"], cresp["attributes"]["name"] )) + tup = ( cresp["id"], cresp["attributes"]["name"] ) + print(tup) + + if "next" not in nextlink: + break + + return complist + +def merge_groups(associated, master): + name_list = [] + combined = associated + master + set_list = Counter(combined) + duplicates_removed = [k for k,v in set_list.items() if v == 1] + if len(duplicates_removed) > 0: + for groups in duplicates_removed: + name = groups[1] + name_list.append(name) + else: + name_list = "None" + return name_list + +def get_course(): + groups = get_groups() + count = 0 + courses = [] + + while True: + count += 1 + url = f"https://api2.northpass.com/v2/courses?page={count}" + data = requests.get(url, headers=HEADERS).json() + nextlink = data["links"] + + for response in data["data"]: + status = response["attributes"]["status"] + if status == "live": + uuid = response["id"] + name = response["attributes"]["name"] + if name.startswith('Category Advisor'): + print("COURSE NAME") + print(name) + print("----------") + associated_list = compare_groups(uuid) + final_groups = merge_groups(associated_list, groups) + course_dict = { + "id": uuid, + "name": name, + "status": status, + "groups" : final_groups + } + courses.append(course_dict) + cat_id = response["relationships"]["categories"]["data"] + get_cat_name(cat_id, course_dict, courses) + + if "next" not in nextlink: + break + +def get_cat_name(cat_id, course_dict, courses): + if len(cat_id) == 0: + cats = ["None"] + else: + cats = [] + for item in cat_id: + categoryid = item["id"] + url = f"https://api2.northpass.com/v2/categories/{categoryid}" + cat_data = requests.get(url, headers=HEADERS).json() + cat_name = cat_data["data"]["attributes"]["name"] + cats.append(cat_name) + course_dict.update({"categories": cats}) + + write_to_csv(courses) + + +def write_to_csv(courses): + df = pd.DataFrame.from_dict(courses) + df.to_csv("/Users/normrasmussen/Downloads/supplier_courses.csv") + + +if __name__ == "__main__": + get_course() diff --git a/Tasks.md b/Tasks.md index deb256d3..34d9e389 100644 --- a/Tasks.md +++ b/Tasks.md @@ -4,7 +4,7 @@ - [ ] Ask if product will add an export button to the new access tab or have a dashboard around enrollment source. - 04-22-2025 ## Arbor Education -- [ ] Check that billing contact is not Claire. - 04-22-2025 +- [X] Check that billing contact is not Claire. - 04-22-2025 - [ ] Move academy to open access & upload domain blocking code - 04-22-2025 ## BuilderTrend @@ -17,9 +17,9 @@ ## Notes ## Other Admin -- [-] Await Lukasz direction on changing the Artera and Hanna University Looks once the new explores are created. - 04-24-2025 -- [-] Clean up Walmart Mexico S3 bucket. Wait for Hubert to share what he wants to do. - 04-24-2025 -- [ ] Workato webhook endpoint update. See thread with Austin, Tom, etc. - 05-01-2025 +- [X] Await Lukasz direction on changing the Artera and Hanna University Looks once the new explores are created. - 04-24-2025 +- [X] Clean up Walmart Mexico S3 bucket. Wait for Hubert to share what he wants to do. - 04-24-2025 +- [X] Workato webhook endpoint update. See thread with Austin, Tom, etc. - 05-01-2025 ## Pipedrive @@ -37,7 +37,7 @@ - [X] Add all users in CSV to "Active Supplier", "All Users", and "Grow with Walmart" groups. Set Locale-Person to USA. ## Walmart Volt -- [ ] Start compiling ticket list and notes to send to Dan Kardell. - 04-23-2025 +- [X] Start compiling ticket list and notes to send to Dan Kardell. - 04-23-2025 ## Williams-Sonoma - [X] Revert auto-adding of badges to post-new hire dash. Badges should only show when course `ef6af62f-897e-4eb2-8f0f-47b3df3bc06b` is completed. - 04-15-2025 @@ -49,4 +49,4 @@ - [X] Custom fields on user records - (CE Props) - available in analytics - [X] Can SJ API add sign up fields progromatically - [X] Can we make a custom page that has a custom title. Use this as a landing page instead of an email -- [ ] Book EMC meeting for Courtney and Lila/Alisha. - 05-09-2025 +- [ ] Book EMC meeting for Courtney and Alisha. - 05-09-2025