-
Notifications
You must be signed in to change notification settings - Fork 0
/
clalit_slot_check.py
71 lines (54 loc) · 1.88 KB
/
clalit_slot_check.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import winsound
from datetime import datetime
from random import randint
from time import sleep
import requests
from notify_run import Notify
FOUND_BEEP_FREQUENCY = 400
FOUND_BEEP_DURATION = 5000
ERROR_BEEP_FREQUENCY = 200
ERROR_BEEP_DURATION = 2000
def check_slot():
try:
r = requests.get(url=request_url, headers=request_headers)
except Exception as e:
print(e)
print(f"{datetime.now().strftime('%H:%M')}: Too many requests!")
winsound.Beep(frequency=ERROR_BEEP_FREQUENCY,
duration=ERROR_BEEP_DURATION * 2)
sleep(600)
return
r = json.loads(r.content)
curr_time = datetime.now().strftime('%H:%M')
if r['errorType'] == 0:
available_days = r['data']['availableDays']
notify.send(f"SLOT FOUND! {available_days}")
print(f"{curr_time}: {available_days}")
winsound.Beep(frequency=FOUND_BEEP_FREQUENCY,
duration=FOUND_BEEP_DURATION)
elif r['errorType'] == 1:
print(f"{curr_time}: No slots")
else:
print(f"{curr_time}: Connection error, {r}")
winsound.Beep(frequency=ERROR_BEEP_FREQUENCY,
duration=ERROR_BEEP_DURATION)
sleep(180 + randint(0, 60))
if __name__ == '__main__':
notify = Notify() # Need to register at first run: notify.register()
print("Paste request headers:")
lines = []
while True:
line = input()
if line:
lines.append(line)
else:
break
request_headers = {}
for p in lines[1:]:
key, val = str.split(p, sep=': ')
request_headers[key] = val
request_url = f"https://{request_headers['Host']}{str.split(lines[0], sep=' ')[1]}"
print("Processed request headers, starting requests.")
while True:
check_slot()