-
Notifications
You must be signed in to change notification settings - Fork 4
/
patient_nu.py
55 lines (39 loc) · 1.59 KB
/
patient_nu.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
from datetime import datetime
import time
from time import mktime
from service.downloader import Downloader
BASE_URL = 'https://patient.nu/portal/public/gettimes/'
DATE_STRUCT = "%Y-%m-%d"
NO_SLOTS = {'next': None, 'amount_of_slots': 0}
def get_slots(id, start_date, end_date):
start = start_date.strftime(DATE_STRUCT)
end = end_date.strftime(DATE_STRUCT)
url = '{}{}?start={}&end={}'.format(BASE_URL, id, start, end)
headers = {
'User-Agent': 'PostmanRuntime/7.28.0',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
}
return Downloader.get_json_with_headers(url, headers)
def get_next_time_and_slots(id, start_date, end_date):
slots = get_slots(id, start_date, end_date)
available_slots = []
if slots != []:
for slot in slots:
if 'Bokad' not in slot['title']:
available_slots.append(date_from(slot['start']))
return {
'next': available_slots[0] if len(available_slots) > 0 else None,
'amount_of_slots': len(available_slots)
}
def get_id_from_url(url):
return url.replace('https://patient.nu/portal/public/calendar/', '')
def date_from(date_and_time):
if '000000Z' in date_and_time:
struct = time.strptime(date_and_time, "%Y-%m-%dT%H:%M:%S.000000Z")
elif '+02:00' in date_and_time:
struct = time.strptime(date_and_time, "%Y-%m-%dT%H:%M:%S+02:00")
else:
struct = time.strptime(date_and_time, "%Y-%m-%dT%H:%M:%S+01:00")
return datetime.fromtimestamp(mktime(struct))