-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_lecture.py
65 lines (43 loc) · 1.71 KB
/
get_lecture.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
"""Get a lecture from the Climate Compatible Curriculum
Writes a markdown file with the contents of the lecture to the current directory
>>> python get_lecture.py
"""
import requests
from typing import Dict, Union, Any
def get_lecture(id: str):
"""Retrieves the contents of a lecture from the teaching kit website
Arguments
---------
id (str): The id of the lecture block to retrieve
"""
url = f"https://teachingkit.climatecompatiblegrowth.com/api/lectures/{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__":
lecture = get_lecture(2)
attributes = lecture['data']['attributes']
print(f"Attributes: {attributes.keys()}")
blocks = attributes['Blocks']['data']
print(blocks)
for block in blocks:
print(f"This lecture contains block {block['id']}: '{block['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']}")
outcomes = [x['LearningOutcome'] for x in attributes['LearningOutcomes']]
print(f"Outcomes: {outcomes}")
title = attributes['Title']
print(title)
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)