Commit bc05fbeb authored by Mohith Jagalmohanan's avatar Mohith Jagalmohanan

Python file

parents
# Check: https://documenter.getpostman.com/view/9564387/TzRPip7u#bc8f4d99-fdf8-4742-8d8c-c916e2be2371
import requests
import pgeocode
import time
import datetime
distFinder=pgeocode.GeoDistance('in')
def vaccineFound(each):
each['session_id'] = each['sessions'][0]['session_id']
each['date'] = each['sessions'][0]['date']
each['available_capacity'] = each['sessions'][0]['available_capacity']
each['min_age_limit'] = each['sessions'][0]['min_age_limit']
each['allow_all_age'] = each['sessions'][0]['allow_all_age']
each['vaccine'] = each['sessions'][0]['vaccine']
each['slots'] = each['sessions'][0]['slots']
each['available_capacity_dose1'] = each['sessions'][0]['available_capacity_dose1']
each['available_capacity_dose2'] = each['sessions'][0]['available_capacity_dose2']
del each['sessions']
date_now=datetime.datetime.now().strftime('%d-%m-%Y')
time_now=datetime.datetime.now().strftime('%H:%M:%S')
for i in each:
string=i.replace("_"," ").title()
if(string=="Lat"): string="Lattitude"
elif(string=="Long"): string="Longitude"
print("{}: {}".format(string,each[i]))
print("Current Time/Date: {} {}".format(time_now,date_now))
print("Air Distance: {}".format(distFinder.query_postal_code("691305",each["pincode"])))
for i in range(3):
print('\a')
time.sleep(0.25)
return True
def findAvailability(date,pin_list,header):
counter = 0
pincodes=[]
data=[]
for pincode in pin_list:
URL = 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={}&date={}'.format(pincode, date)
result = requests.get(URL, headers=header)
response_json = result.json()
data = data+response_json["centers"]
for datum in data:
each=datum['sessions'][0]
if((each["available_capacity_dose2"] >= 0) & (each["min_age_limit"] == 45) and (each["vaccine"] == "COVISHIELD")):#Dose:2 for age:45
counter += 1
vaccineFound(datum)
else:
pincodes=pincodes+[datum["pincode"]]
if(counter == 0):
print("No Available Slots",datetime.datetime.now())
return False
###################################################################
dist_list = [300,298,296]
date=datetime.datetime.now()
date=date.strftime('%d-%m-%Y') #Current date is part of checklist
#days_ahead=6
date=datetime.datetime.strptime('02-07-2021','%d-%m-%Y')
#for i in range(days_ahead):
# day=day+datetime.timedelta(1)
# date=day.strftime('%d-%m-%Y')
# date_list=date_list+[date]
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}
PTY=[]
QLN=[]
TRV=[]
#QLN=[689695,689696,691002,691004,691005,691305,691306,691308,691309,691310,691333,691503,691505,691508,691520,691522,691534,691535,691536,691541,691559]
#TRV=[691533]
#PTY=[689501,689546,689586,689656,689664,689691,690561]
QLN=[691305,691309,691308,689696,691333]
pin_list=QLN+TRV+PTY
while(True):
time.sleep(3)
#print('\a')
findAvailability(date,pin_list,header)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment