Skip to content

Commit

Permalink
fixed request error in vaccine data fetching. added logging facility
Browse files Browse the repository at this point in the history
  • Loading branch information
sridharjena97 committed May 18, 2021
1 parent c9b9a06 commit 7cb2191
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions find_slots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import requests
import datetime
import json
import pandas as pd
from time import sleep
from fake_useragent import UserAgent
from win10toast import ToastNotifier
Expand All @@ -13,7 +12,7 @@

## Important Variables
# 0 = Search entire state, 1 = Search only a single district
method = 1
method = 0

# Set state code or district code 0 to query state and district code list
state_code = 0
Expand Down Expand Up @@ -58,15 +57,14 @@ def printCodes():
base = datetime.datetime.today()
date_list = [base + datetime.timedelta(days=x) for x in range(numdays)]
date_str = [x.strftime("%d-%m-%Y") for x in date_list]


print(date_str)
def checkDistrict(DIST_ID):
global print_detailed
global age
none_found = 1
for INP_DATE in date_str:
URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id={}&date={}".format(DIST_ID, INP_DATE, headers=browser_header)
response = requests.get(URL)
URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id={}&date={}".format(DIST_ID, INP_DATE)
response = requests.get(URL, headers=browser_header)
if response.ok:
slots_age = 0
resp_json = response.json()
Expand All @@ -85,13 +83,15 @@ def checkDistrict(DIST_ID):
if(session["vaccine"] != ''):
print("\t Vaccine: ", session["vaccine"])
print("\t Paid: ", center["fee_type"])
with open(f"log_of_age-{age}.log","a") as f:
f.write(f"""{datetime.datetime.now()} Date-{INP_DATE} Center- {center["name"]} Slots - {session["available_capacity"]} {session["vaccine"]}\n""")
try:
n = ToastNotifier()
n.show_toast("Vaccine Available!!!", f"""On -{INP_DATE} at- {center["name"]} slots - {session["available_capacity"]}\n {session["vaccine"]} fees:{center["fee_type"]}""", duration = 10, icon_path ="./icon.ico")
n.show_toast("Vaccine Available!!!", f"""On -{INP_DATE} at- {center["name"]} slots - {session["available_capacity"]}\n {session["vaccine"]} {center["fee_type"]}""", duration = 5, icon_path ="./icon.ico",threaded=False)
except:
pass

else:
print("Respose is not getting through")
if print_detailed==1:
if slots_age==0:
print("\tNo available slots on {} for your age".format(INP_DATE))
Expand All @@ -108,14 +108,15 @@ def createDistrictDictionary(STATE_ID):
return dict

# Execute
if method==1:
checkDistrict(district_code)

if method==0:
dict = createDistrictDictionary(state_code)
for i in dict.keys():
print("\n", i, dict[i], end="")
checkDistrict(i)

print("\nSEARCH COMPLETE.")
sleep(10000)
while True:
if method==1:
checkDistrict(district_code)

if method==0:
dict = createDistrictDictionary(state_code)
for i in dict.keys():
print("\n", i, dict[i], end="")
checkDistrict(i)

print("\nSEARCH COMPLETE.")
sleep(20)

0 comments on commit 7cb2191

Please sign in to comment.