-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·68 lines (53 loc) · 1.6 KB
/
main.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
#!/usr/bin/env python3.8
import logging
import time
import requests
import irc.client
def notify(msg):
client = irc.client.Reactor()
server = client.server()
server.connect("irc.freenode.net", 6667, "hsldzat")
def on_connect(connection, event):
connection.join("#hakierspejs")
def on_join(connection, event):
connection.privmsg("#hakierspejs", msg)
connection.quit()
raise RuntimeError()
client.add_global_handler("welcome", on_connect)
client.add_global_handler("join", on_join)
try:
client.process_forever()
except RuntimeError:
pass
def isitopen():
return bool(
len(
requests.get(
"https://at.hs-ldz.pl/api/v1/users?online=true"
).json()
)
)
def is_status_stable(nowisopen, num_checks):
for i in range(num_checks):
if isitopen() != nowisopen:
return False
time.sleep(60)
return True
def main():
isopen = isitopen()
while True:
time.sleep(600)
nowisopen = isitopen()
if nowisopen and not isopen:
if is_status_stable(nowisopen, num_checks=1):
notify("Spejs jest otwarty! Więcej info: https://at.hs-ldz.pl")
isopen = nowisopen
elif isopen and not nowisopen:
if is_status_stable(nowisopen, num_checks=15):
notify(
"Spejs jest zamknięty! Więcej info: https://at.hs-ldz.pl"
)
isopen = nowisopen
if __name__ == "__main__":
logging.basicConfig(level="DEBUG")
main()