-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze.py
More file actions
executable file
·84 lines (62 loc) · 1.87 KB
/
Copy pathanalyze.py
File metadata and controls
executable file
·84 lines (62 loc) · 1.87 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import json
from os.path import isfile
import requests
def get_db(year, session):
db_path = f'{year}{session}-db.json'
if not isfile(db_path):
_download_db(year, session, db_path)
with open(db_path) as f:
return json.load(f)
def _download_db(year, session, destination):
FIREBASE_DB_URL = f'https://ubc-coursedb.firebaseio.com/{year}{session}.json'
resp = requests.get(FIREBASE_DB_URL)
print(f'GET {resp.url} => {resp.status_code}')
if resp.status_code != 200:
raise Exception('error downloading database')
with open(destination, 'w') as f:
f.write(resp.text)
def unique_activity_types(db):
return {
info['activity'][0]
for dept in db
for course in db[dept]
for section, info in db[dept][course].items()
if info['activity']
}
def unique_days_types(db):
return {
info['days'][0]
for dept in db
for course in db[dept]
for section, info in db[dept][course].items()
if info['days']
}
def sections_without_start_time(db):
return {
section: info
for dept in db
for course in db[dept]
for section, info in db[dept][course].items()
if not info['start_time'] or not info['start_time'][0]
}
def sections_with_more_than_one_activity_type(db):
return {
section: info
for dept in db
for course in db[dept]
for section, info in db[dept][course].items()
if len(info['activity']) > 1
}
def main():
YEAR = '2017'
SESSION = 'W'
db = get_db(YEAR, SESSION)
for days in unique_days_types(db):
print(days)
# for activity in unique_activity_types(db):
# print(activity)
# data = sections_with_more_than_one_activity_type(db)
# print(json.dumps(data))
if __name__ == '__main__':
main()