-
Notifications
You must be signed in to change notification settings - Fork 1
/
poll.py
50 lines (41 loc) · 1.18 KB
/
poll.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
import requests
import json
import time
from playsound import playsound
log = open("poll.log", "a")
def check_all(endpoints, sound):
success = False
for target in endpoints:
res = requests.get(target["url"])
if res.status_code != 200:
print("Error: " + target["name"])
print(res)
continue
log.write(target["name"] + ":\t" + res.text + "\n")
log.flush()
parsed = json.loads(res.text)
if parsed["total"] != 0:
success = True
print("\nAppointments at " + target["name"])
print(parsed)
else:
print(".", end="", flush=True)
if success and sound:
playsound(sound)
def main():
settings_file = open("settings.json", "r")
settings = json.load(settings_file);
settings_file.close()
sound = ""
if "sound" in settings:
sound = settings["sound"]
print("Using alarm sound " + sound)
interval = 3
if "interval" in settings:
interval = settings["interval"]
while True:
check_all(settings["endpoints"], sound)
time.sleep(interval)
log.close()
if __name__ == "__main__":
main()