Home » Python projects » Covid-19 vaccine availability check using Python

Covid-19 vaccine availability check using Python

Covid vaccination slot india cowin portal

The entire world is struggling to get immune against coronavirus by opting for the available covid-19 vaccine as soon as possible. Many countries have started the vaccination program during late 2020 and some of them have successfully vaccinated their entire population by May 2021. India has also started the vaccination drive and with each passing days, more citizens are being vaccinated. Due to the huge population, it is getting difficult to find a slot for the vaccination. The government had made it clear that citizen would be able to take vaccine only by booking online appointments on COWIN portal.

This program is purely for educational purpose and to make you aware of API, released by the government of India, in the Public domain. You will learn to use Python to create a script which will send API GET request (using Python’s requests module) and fetch the JSON data as a response. This code requires the area Pincode and the date for which you want the availability of the vaccine.

Input Required: Area Pincode, Date

Output: List of all the Vaccination center(s) name along-with date-wise data like type of vaccine, minimum age, available slot.

python project list by aipython

Developer: aipython on [12-05-2021]
website: www.aipython.in

This program demonstrates the use case of  COWIN API (available in the public domain) to view the availability of 
vaccine type, Minimum eligible age, Available slot for a particular date and Pincode.

Check for COVID vaccine availability near you using Python | covid vaccine registration India | Python API

import requests #can be installed using:  pip install requests

while len(PINCODE) != 6:
    PINCODE = input("Enter the pincode for which you want the status => ")
    if len(PINCODE) < 6:
        print (f"{PINCODE} is shorter than the actual length")
    elif len(PINCODE) > 6:
        print (f"{PINCODE} is longer than the actual length")
REQ_DATE = input ("Enter the Date to get status (Date format: DD-MM-YYYY) => ")

request_link = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode={PINCODE}&date={REQ_DATE}"
header = {'User-Agent': 'Chrome/84.0.4147.105 Safari/537.36'}
response = requests.get(request_link, headers = header)
raw_JSON = response.json()

Total_centers = len(raw_JSON['centers'])
print ()
print ("                        *>>>>>>    RESULTS   <<<<<<<*                                ")
print ("-------------------------------------------------------------------------------------")
print (f"Date: {REQ_DATE} | Pincode: {PINCODE} ")

if Total_centers != 0:
    print (f"Total centers in your area is: {Total_centers}" )
    print (f"Unfortunately !! Seems like no center in this area / Kindly re-check the Pincode" )

print ("------------------------------------------------------------------------------------")
print ()

for cent in range(Total_centers):
    print ()
    print (f"[{cent+1}] Center Name:", raw_JSON['centers'][cent]['name'])
    print ("------------------------------------------------------------")
    print ("   Date      Vaccine Type    Minimum Age    Available ")
    print ("  ------     -------------   ------------   ----------")
    this_session = raw_JSON['centers'][cent]['sessions']
    for _sess in range(len(this_session)):
        print ( "{0:^12} {1:^12} {2:^14} {3:^16} ".format(this_session[_sess]['date'], this_session[_sess]['vaccine'], this_session[_sess]['min_age_limit'], this_session[_sess]['available_capacity']))

Result – Python script COVID-19 vaccine availability

covid-19 vaccine status on cmd window
Result window showing each center with all details

Scroll to Top