Get an automated email on availability of Covishield and Covaxin on Cowin-SaralGyaan

Udit Vashisht
3 min readMay 6, 2021

How to get an automated email on availability of Covishield and Covaxin on Cowin website?

I have created a Python Script which can be used to send automated email if the COVID-19 Vaccine (Covishield or Covaxin) is available on the Indian Government’s Cowin Portal for any age group (18 + or 45+). This script has been built by using the API provided by the Government.

You can either run this script locally on your computer or on a Raspberry PI or can host your script on Digital Ocean.

Prerequisites

  • A gmail account and password.
  • An app password if you have 2-Step Verification enabled on your gmail account. Follow this link to learn to setup your account.

Note: You can also use other email accounts but for that you will have to change email server and PORT at line 66 of the code (cowin-email-alerts.py)

Requirements

  • Python 3.9 or above (As the code uses f-strings)
  • cowin (pip install cowin)
  • pandas

You can use the following command to install all the requisite modules:-
pip install -r requirements.txt

Installation

Either download the directory from github or clone it using:-

https://github.com/uditvashisht/cowin-gmail-alerts.git

cd cowin-gmail-alerts python3 -m venv . #You can use python or python3 or python3.6 depending on your system source bin/activate pip install -r requirements.txt

Usage

Adding your email credentials

You can add the FROM_EMAIL, TO_EMAIL, PASSWORD (for FROM_EMAIL) either at line 11–13 of the python code (cowin-email-alerts.py) or
your can use python-decouple or environment variables

FROM_EMAIL = config('FROM_EMAIL') 
TO_EMAIL = config('TO_EMAIL')
PASSWORD = config('PASSWORD')

Create a .env file and add your credentials

FROM_EMAIL= 
TO_EMAIL=
PASSWORD=

Then you need to provide the following:-

  1. No. of Days :- It should be added in line 16 of the code. Preferably 7,14,21 or 28 days should be added if add between 14 to 20 days it will give data for 14 days.
  2. Pincodes :- You can add any number of pincodes in line 17. But the pincodes should be added as string separted by commas in a list. e.g [‘141001’, ‘152002’, ‘152001’]
  3. Age :- To be added in line 18 of the code. Acceptable values are 18 or 45.
# Just Change these values 
no_of_days = 28 # Change this to 7,14,21 or 28
pincodes = ['141001', '141002'] # Add as many pincodes as you want separated by commas
min_age_limit = 18 # Change this to 18 if you want 18+

Then the script can be run as

python cowin-email-alerts.py

Your will get an email like this :-

You can either schedule to run the script at regular intervals or run it in the background after commenting out line 132 and uncommenting lines 136–138 of the code. It will run the script and check for the availability after every 15 minutes till you keep it running.

if __name__ == '__main__': 
main() # comment this
# If you want to continuosly run it in background comment the above line and uncomment the following lines and the function will be repeated after every 15 minutes
# while True:
# main()
# time.sleep(900)

Note:- You might change the name in the message at line 63 and the subject at line 57

message['Subject'] = 'Covid Vaccination Slot is available' message['From'] = FROM_EMAIL 
message['To'] = TO_EMAIL
with open(text_file, 'r') as f:
contents = f.readlines()
text = '\n'.join(contents)
final_text = f'Dear Udit,\n\n Covid Vaccination slots are available at the following locations\n {text} \n\nRegards,\n Udit'

Ways to Support Us

If you have liked this post, there are few ways in which you can support us:-

You can join and contribute on Patreon or you can contribute through Paypal

In addition to that you can show your support by following our social accounts or by simply sharing this post.
1. Facebook
2. Twitter
3. Instagram
4. Youtube

Originally published at https://saralgyaan.com.

--

--