Last active
May 1, 2021 08:32
-
-
Save sengupta/dec88f899f239d86d32ab0e1c71ef7b1 to your computer and use it in GitHub Desktop.
Vaccine slots available for people below 45
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
import sys | |
import json | |
import requests | |
from datetime import datetime | |
current_date = datetime.today().strftime("%d-%m-%y") | |
district_id = 294 # This is Bangalore / BBMP | |
if len(sys.argv) > 1: | |
district_id = int(sys.argv[1]) | |
print(f"Looking for vaccination availability in district ID {district_id}") | |
# Replace the above with your favourite district: | |
# | |
# First, find your state ID: | |
# $ curl -X GET "https://cdn-api.co-vin.in/api/v2/admin/location/states" -H "accept: application/json" -H "Accept-Language: en_IN"| python -m json.tool | |
# | |
# Then find your district ID (replace state ID "21" below with your state ID): | |
# $ curl -X GET "https://cdn-api.co-vin.in/api/v2/admin/location/districts/21" -H "accept: application/json" -H "Accept-Language: en_IN"| python -m json.tool | |
CALENDAR_ENDPOINT = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id={district_id}&date={current_date}" | |
response = requests.get( | |
CALENDAR_ENDPOINT, | |
headers={ | |
'Accept': 'application/json', | |
'Accept-Language': 'en_IN'}, | |
) | |
if response.status_code != 200: | |
print("Something went wrong. Response below:") | |
print(response.status_code) | |
print(response.text) | |
exit() | |
centers = response.json()['centers'] | |
eligible_available_centers = [] | |
SHOW_EMPTY_SLOTS = True | |
for center in centers: | |
for session in center['sessions']: | |
if session['min_age_limit'] != 45: | |
if SHOW_EMPTY_SLOTS or session['available_capacity'] > 0: | |
eligible_available_centers.append((center, session)) | |
if len(eligible_available_centers) == 0: | |
print("Sorry, no available centers. Stay home") | |
exit() | |
for center, session in eligible_available_centers: | |
print(f"{center['pincode']}: {session['available_capacity']} slots available at {center['name']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment