2023-11-17 17:18:13 -05:00
|
|
|
import Apikeys
|
|
|
|
|
import requests
|
2024-01-23 16:54:25 -05:00
|
|
|
import pprint
|
|
|
|
|
import csv
|
2023-11-17 17:18:13 -05:00
|
|
|
|
2024-01-23 16:54:25 -05:00
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
2024-03-11 17:03:07 -04:00
|
|
|
APIKEY = Apikeys.WALMARTPROD
|
2023-11-17 17:18:13 -05:00
|
|
|
HEADERS = {
|
|
|
|
|
"accept": "application/json",
|
|
|
|
|
"X-Api-Key": APIKEY,
|
|
|
|
|
}
|
2024-04-19 16:53:56 -04:00
|
|
|
GROUPS = [
|
|
|
|
|
"Accreditation",
|
|
|
|
|
"Anthology 101",
|
|
|
|
|
"Baseline",
|
|
|
|
|
"Course Evaluations",
|
|
|
|
|
"Engage",
|
|
|
|
|
"Evaluate",
|
|
|
|
|
"Finance & HCM",
|
|
|
|
|
"Learn",
|
|
|
|
|
"Portfolio",
|
|
|
|
|
"Power BI",
|
|
|
|
|
"Raise",
|
|
|
|
|
"Reach",
|
|
|
|
|
"Student",
|
|
|
|
|
]
|
2024-01-03 16:22:53 -05:00
|
|
|
|
2023-11-17 17:18:13 -05:00
|
|
|
def get_courses():
|
|
|
|
|
"""
|
|
|
|
|
Function to get courses and their IDs
|
|
|
|
|
"""
|
|
|
|
|
count = 0
|
|
|
|
|
list_of_ids = []
|
|
|
|
|
|
2024-01-08 16:41:01 -05:00
|
|
|
while True:
|
|
|
|
|
# for course_name in COURSES:
|
|
|
|
|
count += 1
|
|
|
|
|
# url = f"https://api.northpass.com/v2/courses/?filter[name][eq]={course_name}"
|
2024-03-11 17:03:07 -04:00
|
|
|
url = f"https://api2.northpass.com/v2/courses/?limit=100&page={count}"
|
2023-11-17 17:18:13 -05:00
|
|
|
response = requests.get(url, headers=HEADERS)
|
|
|
|
|
response = response.json()
|
|
|
|
|
nextlink = response["links"]
|
|
|
|
|
|
|
|
|
|
for item in response["data"]:
|
2024-03-06 17:06:00 -05:00
|
|
|
status = item['attributes']['status']
|
2024-01-31 17:32:20 -05:00
|
|
|
if status == 'live':
|
2024-03-06 17:06:00 -05:00
|
|
|
name = item['attributes']['name']
|
2024-03-11 17:03:07 -04:00
|
|
|
idict = {item["attributes"]["name"]: item["id"]}
|
|
|
|
|
list_of_ids.append(idict)
|
|
|
|
|
# if "[Core]" in name:
|
2023-11-17 17:18:13 -05:00
|
|
|
|
|
|
|
|
if "next" not in nextlink:
|
|
|
|
|
break
|
2024-01-31 17:32:20 -05:00
|
|
|
|
2024-01-23 16:54:25 -05:00
|
|
|
pp.pprint(list_of_ids)
|
2024-01-08 16:41:01 -05:00
|
|
|
# print(len(list_of_ids))
|
2024-01-23 16:54:25 -05:00
|
|
|
with open(
|
2024-03-11 17:03:07 -04:00
|
|
|
"/Users/normrasmussen/Downloads/Walmart-Live-Courses.csv", "a+", newline='\n'
|
2024-01-23 16:54:25 -05:00
|
|
|
) as csvfile:
|
|
|
|
|
for group in list_of_ids:
|
|
|
|
|
for key, value in group.items():
|
|
|
|
|
csvwriter = csv.writer(csvfile)
|
|
|
|
|
csvwriter.writerow([key, value])
|
2023-11-17 17:18:13 -05:00
|
|
|
|
2024-01-03 16:22:53 -05:00
|
|
|
|
2023-11-17 17:18:13 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
get_courses()
|