-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourse_checker.py
More file actions
66 lines (62 loc) · 2.67 KB
/
Copy pathcourse_checker.py
File metadata and controls
66 lines (62 loc) · 2.67 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
import requests
import time
from notify_run import Notify
from interested_courses import interested_courses
import datetime
url = r"https://api.easi.utoronto.ca/ttb/getPageableCourses"
payload = {"courseCodeAndTitleProps":
{"courseCode":"",
"courseTitle":"",
"courseSectionCode":"F",
"searchCourseDescription":"false"
},
"departmentProps":[],
"campuses":[],
"sessions":["20239"],
"requirementProps":[],
"instructor":"",
"courseLevels":[],
"deliveryModes":[],
"dayPreferences":[],
"timePreferences":[],
"divisions":[],
"creditWeights":[],
"page":1,
"pageSize":20,
"direction":"asc"}
headers = {"Accept": "application/json"}
notify = Notify()
frequency = 5 # seconds
availabilities = {i['courseCode']:0 for i in interested_courses}
if __name__ == "__main__":
while True:
for interested_course in interested_courses:
course_payload = dict(payload)
course_payload["courseCodeAndTitleProps"]["courseCode"] = interested_course["courseCode"]
course_payload["courseCodeAndTitleProps"]["courseTitle"] = interested_course["courseTitle"]
course_payload["divisions"] = interested_course["divisions"]
response = requests.post(url, json=course_payload, headers=headers)
response = response.json()
course = response["payload"]["pageableCourse"]["courses"][0]
sections = course["sections"]
target = interested_course["target"]
for section in sections:
message = course["code"] + " " + course["name"]
if target and section["name"] not in target:
continue
if section["type"] == "Lecture":
message += "\n" + section["name"]
availability = section["maxEnrolment"] - section["currentEnrolment"]
waitlist = section["currentWaitlist"]
message += " Availability: {}".format(availability)
key = course["code"] + " " + section["name"]
if key not in availabilities:
availabilities[key] = 0
prev_availability = availabilities[key]
if availability != prev_availability:
availabilities[key] = availability
message += "\n" + str(datetime.datetime.now())
print(message)
print()
notify.send(message)
time.sleep(frequency)