Files
Gainsight/Scripts/API_Tests/get_courses.py
Norm Rasmussen 5f971353ec Changes?
2023-03-24 15:59:46 -04:00

39 lines
1.0 KiB
Python

import requests
import json
import Apikeys
def get_course():
count = 0
apiKey = Apikeys.walmartprod
live_courses = []
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"]
if status == "live":
name = response["attributes"]["name"]
live_courses.append(name)
with open("/Users/normrasmussen/Downloads/courses.txt", "a") as write:
write.write("\n")
write.write(name)
if "next" not in nextlink:
break
print(live_courses)
if __name__ == "__main__":
get_course()