Changes?
This commit is contained in:
38
Scripts/API_Tests/get_courses.py
Normal file
38
Scripts/API_Tests/get_courses.py
Normal file
@ -0,0 +1,38 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user