Files
Gainsight/Scripts/API_Tests/get_course_ids.py

56 lines
1.5 KiB
Python
Raw Normal View History

import Apikeys
import requests
import pprint
import csv
pp = pprint.PrettyPrinter(indent=4)
2024-11-21 17:02:28 -05:00
APIKEY = Apikeys.EMPLOY
HEADERS = {
"accept": "application/json",
"X-Api-Key": APIKEY,
}
GROUPS = [
]
def get_courses():
"""
Function to get courses and their IDs
"""
count = 0
list_of_ids = []
while True:
# for course_name in COURSES:
count += 1
# url = f"https://api.northpass.com/v2/courses/?filter[name][eq]={course_name}"
2024-11-21 17:02:28 -05:00
url = f"https://api.northpass.com/v2/courses/?limit=100&page={count}"
response = requests.get(url, headers=HEADERS)
response = response.json()
nextlink = response["links"]
for item in response["data"]:
status = item['attributes']['status']
if status == 'live':
name = item['attributes']['name']
2024-11-25 09:41:08 -05:00
print(name)
idict = {item["attributes"]["name"]: item["id"]}
list_of_ids.append(idict)
# if "[Core]" in name:
if "next" not in nextlink:
break
pp.pprint(list_of_ids)
# print(len(list_of_ids))
2024-11-25 09:41:08 -05:00
# with open(
# "/Users/normrasmussen/Downloads/LuminateUS-Courses.csv", "a+", newline='\n'
# ) as csvfile:
# for group in list_of_ids:
# for key, value in group.items():
# csvwriter = csv.writer(csvfile)
# csvwriter.writerow([key, value])
if __name__ == "__main__":
get_courses()