-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcowin.py
42 lines (33 loc) · 1.94 KB
/
cowin.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
import requests #can be installed using: pip install requests
PINCODE = "0"
while len(PINCODE) != 6:
PINCODE = input("Enter the pincode for which you want the status => ")
if len(PINCODE) < 6:
print (f"{PINCODE} is shorter than the actual length")
elif len(PINCODE) > 6:
print (f"{PINCODE} is longer than the actual length")
REQ_DATE = input ("Enter the Date to get status (Date format: DD-MM-YYYY) => ")
request_link = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={PINCODE}&date={REQ_DATE}"
header = {'User-Agent': 'Chrome/84.0.4147.105 Safari/537.36'}
response = requests.get(request_link, headers = header)
raw_JSON = response.json()
Total_centers = len(raw_JSON['centers'])
print ()
print (" *>>>>>> RESULTS <<<<<<<* ")
print ("-------------------------------------------------------------------------------------")
print (f"Date: {REQ_DATE} | Pincode: {PINCODE} ")
if Total_centers != 0:
print (f"Total centers in your area is: {Total_centers}" )
else:
print (f"Unfortunately !! Seems like no center in this area / Kindly re-check the Pincode" )
print ("------------------------------------------------------------------------------------")
print ()
for cent in range(Total_centers):
print ()
print (f"[{cent+1}] Center Name:", raw_JSON['centers'][cent]['name'])
print ("------------------------------------------------------------")
print (" Date Vaccine Type Minimum Age Available ")
print (" ------ ------------- ------------ ----------")
this_session = raw_JSON['centers'][cent]['sessions']
for _sess in range(len(this_session)):
print ( "{0:^12} {1:^12} {2:^14} {3:^16} ".format(this_session[_sess]['date'], this_session[_sess]['vaccine'], this_session[_sess]['min_age_limit'], this_session[_sess]['available_capacity']))