finished workflow for sandata - even though they cancelled the launch! Worked on Anthology's group based course extractions.
This commit is contained in:
77
Scripts/API_Tests/get_courses_from_groups.py
Normal file
77
Scripts/API_Tests/get_courses_from_groups.py
Normal file
@ -0,0 +1,77 @@
|
||||
import Apikeys
|
||||
import requests
|
||||
import pprint
|
||||
import csv
|
||||
|
||||
pp= pprint.PrettyPrinter(indent=4)
|
||||
APIKEY = Apikeys.ANTHOLOGY
|
||||
HEADERS = {
|
||||
"accept": "application/json",
|
||||
"X-Api-Key": APIKEY,
|
||||
}
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
GROUPS = [
|
||||
"Accreditation",
|
||||
"Anthology 101",
|
||||
"Baseline",
|
||||
"Course Evaluations",
|
||||
"Engage",
|
||||
"Evaluate",
|
||||
"Finance & HCM",
|
||||
"Learn",
|
||||
"Portfolio",
|
||||
"Power BI",
|
||||
"Raise",
|
||||
"Reach",
|
||||
"Student",
|
||||
]
|
||||
|
||||
def group_ids():
|
||||
"""
|
||||
Get the group Ids from a list of named groups.
|
||||
"""
|
||||
url = "groups"
|
||||
for group in GROUPS:
|
||||
filter = f"?filter[name][cont]={group} - ("
|
||||
urlreq = f"{BASEURL}{url}{filter}"
|
||||
response = requests.get(urlreq, headers=HEADERS)
|
||||
response = response.json()
|
||||
|
||||
for data in response['data']:
|
||||
print(data['attributes']['name'])
|
||||
id = data['id']
|
||||
get_courses_in_groups(id)
|
||||
|
||||
def get_courses_in_groups(id):
|
||||
"""
|
||||
From the IDs received above, list out all of the courses.
|
||||
"""
|
||||
count = 0
|
||||
courses = []
|
||||
while True:
|
||||
# count += 1
|
||||
url = f"groups/{id}/courses?limit=100"
|
||||
courseurl = f"{BASEURL}{url}"
|
||||
coursereq = requests.get(courseurl, headers=HEADERS)
|
||||
coursedata = coursereq.json()
|
||||
# nextlink = coursedata['links']
|
||||
print(id)
|
||||
# print(coursedata)
|
||||
|
||||
for data in coursedata['included']:
|
||||
if data['attributes']['status'] == 'live':
|
||||
name = data['attributes']['name']
|
||||
id = data['attributes']['share_course_link'].split("/")[5]
|
||||
enrollments = data['attributes']['enrollments_count']
|
||||
created = data['attributes']['created_at']
|
||||
updated = data['attributes']['updated_at']
|
||||
coursedict = {
|
||||
"name": name, "id": id, "enrollments": enrollments,
|
||||
"created at": created, "updated at": updated
|
||||
}
|
||||
courses.append(coursedict)
|
||||
print(courses)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
group_ids()
|
||||
Reference in New Issue
Block a user