From 7cb219175621ee9e39d8eddcd4ef498a23ed1e2c Mon Sep 17 00:00:00 2001 From: sridhar Date: Tue, 18 May 2021 13:40:25 +0530 Subject: [PATCH] fixed request error in vaccine data fetching. added logging facility --- find_slots.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/find_slots.py b/find_slots.py index 0704ec6..d6be38b 100644 --- a/find_slots.py +++ b/find_slots.py @@ -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 @@ -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 @@ -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() @@ -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)) @@ -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)