Last active
May 8, 2021 04:30
-
-
Save oyearunpal/9af54787ac1e8047e4d7f98bdf0574e4 to your computer and use it in GitHub Desktop.
Find if there is any covid slot available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import requests | |
import pandas as pd | |
import ast | |
import json | |
import sys | |
import subprocess | |
import os | |
# mail part will only work if you have smtp setup available | |
#sys.path.insert(1,'/home/arun/scripts/') | |
#from send_mail import send_mail | |
date=datetime.now().strftime("%d-%m-%Y") | |
by_pincode_url="https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=400059&date=03-05-2021" | |
mumbai_district="395" | |
min_age=18 | |
#min_age=45 | |
by_district_url="https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=%s&date=%s"%(mumbai_district,date) | |
#response = requests.get(by_district_url) | |
#print(response) | |
now_hour = datetime.now().strftime("%Y%m%d%H") | |
os.system("touch slot.ini") | |
f=open("slot.ini","r") | |
old_hour = f.read() | |
# This is to prevent getting multiple mails | |
if now_hour == old_hour: | |
exit() | |
message = "" | |
#dict_response = response.json() | |
curl_command = '''curl 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=%s&date=%s' \ | |
-H 'authority: cdn-api.co-vin.in' \ | |
-H 'sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"' \ | |
-H 'accept: application/json, text/plain, */*' \ | |
-H 'sec-ch-ua-mobile: ?0' \ | |
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36' \ | |
-H 'origin: https://www.cowin.gov.in' \ | |
-H 'sec-fetch-site: cross-site' \ | |
-H 'sec-fetch-mode: cors' \ | |
-H 'sec-fetch-dest: empty' \ | |
-H 'referer: https://www.cowin.gov.in/' \ | |
-H 'accept-language: en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' \ | |
--compressed -o out.json'''%(mumbai_district,date) | |
dict_response = subprocess.getoutput(curl_command) | |
f = open("out.json",'r') | |
dict_response = json.loads(f.read()) | |
#print(dict_response,type(dict_response)) | |
df=pd.DataFrame(dict_response['centers']) | |
#print(df) | |
for index, row in df.iterrows(): | |
for s in row['sessions']: | |
if s['available_capacity'] > 0 and s['min_age_limit'] == min_age: | |
message+=("<p> %s Available at %s, pincode %s </p>"%(s['available_capacity'] ,row['name'],row['pincode'])) | |
if len(message) > 0: | |
f=open("slot.ini","w") | |
f.write(now_hour) | |
print("mail sent",message) | |
#send_mail("[email protected]",'Slot Finder',"[email protected]","Slot available",message) | |
df.to_csv("slot.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment