-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_json.py
54 lines (40 loc) · 2.17 KB
/
create_json.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
import json
from courspider.faculty_calendar import FacultyCalendar
from courspider.faculty_calendar_resources.faculty_of_arts_and_science_calendar import FacultyOfArtsAndScienceCalendar
from courspider.faculty_calendar_resources.department import Department
from courspider.faculty_calendar_resources.session import Session
from courspider.faculty_calendar_resources.session import Season
from courspider.faculty_calendar_resources.url import URL
def write_data(data, dest):
file = open(dest, 'w')
file.write(json.dumps(data, indent=4))
def _create_course_data():
cal = FacultyOfArtsAndScienceCalendar(Session(2016, Season.FALL),
URL("http://calendar.artsci.utoronto.ca"))
print('getting department calendars')
deps = cal.get_department_calendars()
course_datas = []
print('getting course datas')
for dep in deps:
for course in dep.get_courses():
course_datas.append(course.to_data())
return {"courses": course_datas}
def create_course_json():
write_data(_create_course_data(), "data/courses.json")
print('course data written')
def _create_department_data():
cal = FacultyOfArtsAndScienceCalendar(Session(2016, Season.FALL),
URL("http://calendar.artsci.utoronto.ca"))
print('getting department calendars')
departments = [department.name for department in cal.get_departments()]
return {"departments": departments}
def create_department_json():
write_data(_create_department_data(), "data/departments.json")
print('department data written')
def create_data_json():
courses = _create_course_data()
departments = _create_department_data()
distribution_requirements = {"distribution_requirements": ["Humanity", "Science", "Social Science"]}
breadth_requirements = {"breadth_requirements": ["1. Creative and Cultural Representations", "2. Thought, Belief, and Behaviour", "3. Society and Its Institutions", "4. Living Things and Their Environment", "5. The Physical and Mathematical Universes"]}
data = {**courses, **departments, **distribution_requirements, **breadth_requirements}
write_data(data, "data/data.json")