-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrack_by_PIN.py
59 lines (51 loc) · 1.85 KB
/
track_by_PIN.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
# importing the requests library
import requests
import time
import os
from datetime import date
from datetime import datetime
# api-endpoint
pincodes = ['560008', #Add a list of pins to track
'560030',
'560078',
'560076',
'560002',
'560037',
'560020',
'560034',
'560041',
'560001',
'560066',
'560003',
'560010',
'560011',
'560100']
date_var = date.today().strftime("%d-%m-%Y")
def alert(name):
os.system('spd-say "The vaccine is available at {}"'.format(name))
# sending get request and saving the response as response object
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"}
while True:
for pincode in pincodes:
time.sleep(3.5)
URL = "http://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=" + pincode + "&date=" + date_var
try:
r = requests.get(url=URL, headers=headers)
except requests.ConnectionError:
print("No Network at " + str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))
continue
print(r.status_code)
data = r.json()
flag = 0
for center in data['centers']:
for session in center['sessions']:
if session['available_capacity'] > 3 and session['min_age_limit'] < 45 and session['vaccine'] == 'COVAXIN':
# if session['available_capacity'] > 0:
alert(center['name'])
print(center['name'])
time.sleep(4)
print(session)
flag = 1
if flag == 0:
print("Not available at " + str(datetime.now().strftime("%d/%m/%Y %H:%M:%S")))