Files
Gainsight/Scripts/API_Tests/get_courses.py
2023-03-29 18:06:13 -04:00

49 lines
1.4 KiB
Python

import requests
import json
import Apikeys
def get_course():
count = 0
apiKey = Apikeys.walmartprod
courses = []
category_ids = []
while True:
count += 1
url = f"https://api2.northpass.com/v2/courses?page={count}"
headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers)
data = response.json()
nextlink = data["links"]
jsonResponse = response.json()
jsonResponse = json.dumps(jsonResponse, indent=2)
for response in data["data"]:
status = response["attributes"]["status"]
uuid = response["id"]
name = response["attributes"]["name"]
course_url = f"https://walmart.northpass.com/app/courses/{uuid}"
cat_id = response["relationships"]["categories"]["data"]
for item in cat_id:
categoryid = item["id"]
print(categoryid)
courses.append(name)
with open("/Users/normrasmussen/Downloads/courses.csv", "a") as write:
write.write("\n")
write.write(name+","+status+","+uuid)
if "next" not in nextlink:
break
#print(courses)
# https://walmart.northpass.com/app/courses/
def get_category_name(category_ids):
pass
if __name__ == "__main__":
get_course()