How I created a vaccine available desktop notifier app using only python

How I created a vaccine available desktop notifier app using only python

In India, from 28th April,2021 onwards registration for COVID vaccination started for all the people who are above 18. So it was like a challenge for me to go everyday and check the available slots, which was repetitive job and sometimes even I forgot to check the slots. Also new slots allocation is done randomly so whenever I visit the website I have always seen that slots are booked and honestly speaking I can't monitor the website 24X7 for availability of slots then I thought of creating a script for monitoring availability of the slots. Fortunately, Ministry of Health and Family Welfare made Co-WIN Public APIs to find appointment availabilty and to download vaccination certificates. You can find the complete details of the APIs here.

What does this application do?

The python script is executed periodically as per set frequency in the python scheduler and once the slot is available for mentioned age group in mentioned district/PIN code area, you will be notified through desktop notification message.

For understanding purpose, I have divided the application in three parts:

  • To fetch the details using Co-WIN Public APIs

  • Script to send the desktop notification message whenever the slot is available in intended area

  • Python scheduler to execute script periodically.

So let's take the overview of the code.

First things first, below are the prerequisites:

  • Python 3.x should be installed in your computer. You can download python from link

  • And obviously internet connection

And we are all set to go.

  • To fetch the details using Co-WIN Public APIs:

I have created separate functions for getting state details(state name and id), district details(district name and ID), slots by district(fetch the slots available in complete district) and slots by PIN(fetch the slots available for particular PIN code area).

We need to fetch the state list and district list because in response we will get the state and district ids which we will need to get the details of the available slots from other APIs.

The most important points while sending the requests to CoWIN APIs are:

These APIs are subject to a rate limit of 100 API calls per 5 minutes per IP.

These APIs only work for Indian IPs, that means if you try to access them from outside India you won't be able to access them, you will receive 403 error.

So while sending the requests to these APIs, keep in mind the count per 5 minutes should be less than 100. If the requests count exceeds the threshold limit then your IP will be blocked temporarily. Also if you are working on any VPN network then you may face issue while running the script because it may be using IPs outside the India.

While calling function get_slot_by_district() : actual API calls are 3

While calling function get_slot_by_pin() : actual API call is 1

I am providing this information so that while setting up the frequency to run the script in environment variable, calculate the total request count while selecting the option to execute the script.

  • Second important part is sending the notification to the desktop.

Here plyer module comes to rescue. You can see the more information regarding it here. The basic code for notification is:

from plyer import notification

def send_notification(title, message, timeout):

    notification.notify(title= title,
                        message= message,
                        app_icon = None,
                        timeout= 15,
                        toast=False)

The code is quite simple, isn't it!

Now let's move to the next important step

  • Python scheduler to execute script periodically:

I have used 'schedule' module to schedule the script periodically. You will find the more information about it in link . The code for scheduling the script is also quite simple.

schedule.every(int(frequency)).seconds.do(main)
while True:
    schedule.run_pending()
    time.sleep(1)

I am not giving installation instructions per module because everything is listed in requirements.txt file in github repository. you just need to follow the steps mentioned in readme.md file.

  • How to run this script? If you want to check the slots for particular district with minimum age limit 45 then the command will be like given below:
python executer.py district Maharashtra Mumbai 45

If you want to check the slots for particular PIN id with minimum age limit 18 then the command will be like given below:

python executer.py pin 431001 45

Below is the screenshot of the notification we receive when the slot is available in intended area, in notification you will only see the name of the slot available centers, if you want to see the complete details of the centers then check exec.log file:

image.png

You can see the detailed code and setup steps in github repository . If you find the code useful then drop a star on the repo. Also share this article with all your friends, colleagues and family so that they will also get notified whenever the slot is available in nearby area.