-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcowin.py
162 lines (145 loc) · 5.58 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
Created on Sun May 9 13:42:59 2021
@author: kunal
"""
import requests
import time
from playsound import playsound
import datetime
import traceback
import sys
headers_dict= {
"Accept":"*/*",
"Accept-Encoding":"gzip, deflate, br",
"Connection":"keep-alive",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
};
dates = []
pinCodes = []
dose=1
vaccine_pref='any'
price_pref='any'
min_age_limit=18
def check_appointment(pinCode):
base_url="https://cdn-api.co-vin.in/api/v2"
session_url="/appointment/sessions/public/findByPin?pincode="
for checkdate in dates:
final_url=base_url+session_url+pinCode+"&date="+checkdate;
#print (final_url)
time.sleep(3)
try:
response = requests.get(final_url, headers=headers_dict)
#print(response)
if (200 != response.status_code):
continue
sessions = response.json()
for session in sessions["sessions"]:
if (
(
(18 == min_age_limit and session["min_age_limit"] == 18)
or
(45 == min_age_limit and session["min_age_limit"] == 45)
)
and
(
(dose == 1 and session["available_capacity_dose1"] > 0)
or
(dose == 2 and session["available_capacity_dose2"] > 0)
) and
(
(vaccine_pref =='any')
or
(vaccine_pref =='COVISHIELD' and str(session["vaccine"]).upper().startswith('COVISHIELD'))
or
(vaccine_pref =='COVAXIN' and str(session["vaccine"]).upper().startswith('COVAXIN'))
or
(vaccine_pref =='SPUTNIK' and str(session["vaccine"]).upper().startswith('SPUTNIK'))
) and
(
(price_pref == 'any')
or
(price_pref == 'paid' and str(session["fee_type"]).lower() == 'paid')
or
(price_pref == 'free' and str(session["fee_type"]).lower() == 'free')
)
):
print()
if (session["available_capacity"] > 10):
playsound("CarAlarm.mp3")
print (datetime.datetime.now())
print ("name: ",session["name"])
print ("pincode: ",session["pincode"])
print ("vaccine: ",session["vaccine"])
print ("fee_type: ",session["fee_type"])
print("available:", session["available_capacity"])
print("available dose 1:", session["available_capacity_dose1"])
print("available dose 2:", session["available_capacity_dose2"])
print("date: ",session["date"])
#if (session["available_capacity"] > 10):
#playsound("CarAlarm.mp3")
except:
pass
#traceback.print_exc()
def pinCodeNotValid (pinCodeInput):
global pinCodes
pins = pinCodeInput.split(",")
for pin in pins:
if (len(pin.strip()) != 6) :
return True
if (not pin.strip().isdigit()):
return True
pinCodes.append(pin.strip())
def getDates():
global dates
today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1)
dayAfterTomorrow = today + datetime.timedelta(days = 2)
#d1 = today.strftime("%d-%m-%Y")
#dates.append(d1)
d2 = tomorrow.strftime("%d-%m-%Y")
dates.append(d2)
d3 = dayAfterTomorrow.strftime("%d-%m-%Y")
dates.append(d3)
try:
age_input = input ("Enter Age Category 1. under 45 2. 45 and above : ")
if (age_input.strip() == '2'):
min_age_limit = 45
else:
min_age_limit = 18
pinCodeInput = input ("Enter the PinCode in comma seperated e.g. single pincode 110011 - more than one 110011,110022,110023 : ")
if (pinCodeNotValid(pinCodeInput.strip())):
print ("Invalid pincode(s)")
sys.exit()
vaccine = input ("Vaccine preference - 0 for any, 1 for covishield, 2 for covaxin, 3 for sputnik : ")
if (vaccine.strip() == '1'):
vaccine_pref = 'COVISHIELD'
elif (vaccine.strip() == '2'):
vaccine_pref = 'COVAXIN'
elif (vaccine.strip() == '3'):
vaccine_pref = 'SPUTNIK'
price = input ("Cost Preference - 0 for any, 1 for paid only, 2 for free only : ")
if (price.strip() == '1'):
price_pref = 'paid'
elif (price.strip() == '2'):
price_pref = 'free'
doseDetail = input ("Enter 1 for dose1, 2 for dose2 alert : ")
if (doseDetail.strip().lower() == '1'):
dose=1
elif (doseDetail.strip().lower() == '2'):
dose=2
else:
print ("Enter either 1 for dose1 or 2 for dose2 : ")
sys.exit()
getDates()
print ("Checking for dates -"+str(dates)+" dose -"+str(dose)+ " pincode(s) -"+str(pinCodes)+" vaccine-"+vaccine_pref+" cost preference-"+price_pref+" min age "+str(min_age_limit))
while (1):
for pinCode in pinCodes:
check_appointment(pinCode)
except:
print()
print()
print ("stopping script ...")
print ("error occured")
traceback.print_exc()
finally:
waitClose = input ("Press enter to exit ...")