-
Notifications
You must be signed in to change notification settings - Fork 1
/
iserv.py
56 lines (49 loc) · 1.25 KB
/
iserv.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
"""
An API to communicate with Iserv
"""
from requests import Session
import json
class IServ:
"""
An IServ server
"""
session: Session
iserv: str
def __init__(self, iservName) -> None:
self.session = Session()
self.iserv = iservName
def login(self, username: str, password: str) -> None:
"""
Login into a iserv account and saves session
"""
self.session.post(
f"https://{self.iserv}/iserv/auth/login",
data={
"_username": username,
"_password": password
}
)
def getTimetable(self, startDate: str, endDate: str, schoolClass: str) -> dict:
"""
Gets the timetable from your Iserv account
"""
requestString = (
f' https://{self.iserv}/iserv/timetable/data?'
' filter={'
f' "startDate": "{startDate}",'
f' "endDate": "{endDate}",'
' "changesUntil": null,'
f' "classes":["{schoolClass}"],'
' "teachers":["%"],'
' "rooms":["%"]'
' }'
).replace(" ", "")
timetable = self.session.get(
requestString
)
return json.loads(timetable.content)
def logout(self) -> None:
"""
Logs out of the account
"""
self.session.post(f"https://{self.iserv}/iserv/auth/logout")