-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_course.py
68 lines (44 loc) · 1.8 KB
/
get_course.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Get a course from the Climate Compatible Curriculum
Writes a markdown file with the contents of the course to the current directory
>>> python get_course.py
"""
import requests
from typing import Dict, Union, Any
from get_lecture import get_lecture
from get_block import get_lecture_block
def get_course(id: str):
"""Retrieves the contents of a course from the teaching kit website
Arguments
---------
id (str): The id of the course to retrieve
"""
url = f"https://teachingkit.climatecompatiblegrowth.com/api/courses/{id}?locale=en&populate=*"
response = requests.get(url)
return response.json()
def print_keys(dict: Union[Dict, Any]):
if isinstance(dict, Dict):
for key in dict.keys():
print(key)
print_keys(dict[key])
else:
pass
if __name__ == "__main__":
course = get_course(2)
attributes = course['data']['attributes']
print(f"Attributes: {attributes.keys()}")
title = attributes['Title']
print(f"Course title: {title}")
outcomes = [x['LearningOutcome'] for x in attributes['LearningOutcomes']]
print(f"Outcomes: {outcomes}")
lectures = attributes['Lectures']['data']
for lecture in lectures:
print(f"This course contains lecture: '{lecture['id']}: {lecture['attributes']['Title']}'")
# authors = [x['attributes'] for x in attributes['LectureCreators']['data']]
# print("This lecture lecture was written by:")
# for author in authors:
# print(f"{author['FirstName']} {author['LastName']} {author['Email']} {author['ORCID']}")
# lecture_id = lecture['data']['id']
# document = attributes['Abstract']
# with open(f"lecture_{lecture_id}.md", 'wt') as markdown_file:
# markdown_file.write(f"# {title}\n\n")
# markdown_file.write(document)