-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolito_client.py
40 lines (32 loc) · 1022 Bytes
/
polito_client.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
import requests
import json
from pprint import pprint
from datetime import datetime
class Client:
def __init__(self, token):
self.token = token
def getRooms(self, criteria):
# pprint(criteria)
url = 'https://app.didattica.polito.it/aule_libere.php'
payload = {
"regID": self.token
}
date_param = criteria.get('date')
time_param = criteria.get('time')
if date_param:
payload['giorno'] = date_param
else:
# provide current day
payload['giorno'] = datetime.now().strftime('%d/%m/%Y')
if time_param:
payload['ora'] = time_param
else:
# provide current time
payload['ora'] = datetime.now().strftime('%H:%M:%S')
response = requests.post(
url, data={'data': json.dumps(payload)}).json()
res_data = response.get('data')
if not res_data:
# not ok
return None
return res_data