forked from bntan/doctolib-covid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
doctolib-covid.py
107 lines (87 loc) · 4.93 KB
/
doctolib-covid.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import datetime
import webbrowser
import requests
import smtplib, ssl
import time
DISABLE_EMAIL = os.environ.get("DISABLE_EMAIL")
SENDER_EMAIL = os.environ.get("SENDER_EMAIL")
SENDER_PASSWORD = os.environ.get("SENDER_PASSWORD")
#RECEIVER_EMAIL = os.environ.get("RECEIVER_EMAIL")
with open('centers.txt') as centers_txt:
centers = centers_txt.readlines()
centers = [center.strip() for center in centers if not center.startswith("#")]
with open('emails.txt') as emails_txt:
emails = emails_txt.readlines()
emails = [email.strip() for email in emails if not email.startswith("#")]
with open('vaccines.txt') as vaccines_txt:
vaccines = vaccines_txt.readlines()
vaccines = [vaccine.strip() for vaccine in vaccines if not vaccine.startswith("#")]
try:
while (True):
for center in centers:
data = requests.get(f"https://www.doctolib.de/booking/{center}.json").json()["data"]
#https://www.doctolib.de/booking/ciz-berlin-berlin.json
visit_motives = [visit_motive for visit_motive in data["visit_motives"] if any(vaccine in visit_motive["name"] for vaccine in vaccines)]
if not visit_motives:
continue
places = [place for place in data["places"]]
if not places:
continue
for place in places:
try:
print(" ")
print("Place: " + str(place["formal_name"]))
#start_date = datetime.datetime.today().date().isoformat()
start_date = "2021-06-07"
visit_motive_ids = visit_motives[0]["id"]
practice_ids = place["practice_ids"][0]
place_name = place["formal_name"]
place_address = place["full_address"]
agendas = [agenda for agenda in data["agendas"]
if agenda["practice_id"] == practice_ids and
not agenda["booking_disabled"] and
visit_motive_ids in agenda["visit_motive_ids"]]
if not agendas:
continue
agenda_ids = "-".join([str(agenda["id"]) for agenda in agendas])
#print("visit_motive_ids: " + str(visit_motive_ids))
#print("practice_ids:" + str(practice_ids))
#print("agenda_ids:"+ str(agenda_ids))
response = requests.get(
"https://www.doctolib.de/availabilities.json",
params = {
"start_date": start_date,
"visit_motive_ids": visit_motive_ids,
"agenda_ids": agenda_ids,
"practice_ids": practice_ids,
"insurance_sector": "public",
"destroy_temporary": "true",
"limit":2
},
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
)
response.raise_for_status()
nb_availabilities = response.json()["total"]
result = str(nb_availabilities) + " appointments available at " + place_name + " - " + place_address
print("result: "+ str(result))
if nb_availabilities > 0:
print("RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN RUNNNNNNNNN")
os.system('play -nq -t alsa synth {} sine {}'.format(0.5, 800))
# open page in web browser
webbrowser.open(
"https://www.doctolib.de/profiles/" + str(data["profile"]["id"]))
if nb_availabilities > 0 and DISABLE_EMAIL != "true":
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context = context) as server:
server.login(SENDER_EMAIL, SENDER_PASSWORD)
for email in emails:
server.sendmail(SENDER_EMAIL, email, result.encode('utf-8'))
print(" --> Alert sent to " + RECEIVER_EMAIL)
except json.decoder.JSONDecodeError:
print("Doctolib might be ko")
except KeyError as e:
print("KeyError: " + str(e))
time.sleep(5)
except KeyboardInterrupt:
print("Mischief managed.")