Simple python script when used with cron, sends automated telegram messages to alert about available Cowin appointment slots.
The python script is executed on a desired schedule using cron or Windows' scheduled tasks. It pings Cowin's server and looks for any vaccination center with available slots. Upon receiving successful response from Cowin, the script sends out telegram messages to your configured group / channel / user.
The message is sent out in the following format:
Name of the vaccination center
Address:
Pincode:
Date:
Time:
Vaccine:
Type:
Fee:
Age Limit:
Available doses:
Dose 1:
Dose 2:
Example:
KDMCG ATRE RANGMANDIR NATYAGRU
Address: SHIVAJI CHOWK BAZAR PETH NEAR SUBHASH MAIDAN BHOIWADA KALYAN WEST
Pincode: 421301
Date: 11-08-2021
Time: 10:00:00-17:00:00
Vaccine: COVAXIN
Type: Free
Fee: 0
Age Limit: 18
Available doses: 98
Dose 1: 0
Dose 2: 98
-
Python3
-
Python packages:
telegram_send==0.25
(If you want the bot to send you messages personally)
requests==2.26.0
-
Preferably a Linux based computer (Even a simple raspberry pi would do). Windows gives weird errors with scheduled tasks.
-
Cron on linux. On Windows, you can use scheduled tasks.
-
Stable and 24x7 internet connection (Setup on a cloud instance if you can)
-
Telegram bot
-
Open botfather chat in telegram messenger.
-
Select
/newbot
command and set a name and username for your new bot (username of your bot should end withbot
). -
Copy the api token of your bot.
-
-
Check if you have git installed on your computer using
git --version
. You should get an output with the version of git installed on your computer:git version 2.25.1
Install git if not installed.
-
Clone the repository using following command in a suitable directory on your computer.:
git clone https://github.com/yashimself/cowin-alerts.git
-
Open a terminal in the cloned folder and install the requirements:
pip install -r requirements.txt
-
Open the
secret.py
file in the cloned folder, and paste the api token of your bot that you copied earlier in front ofapi
variable.
e.g:api = 'your bot api inside the quotes'
-
Now, visit telegram web and open the chat where you would like the bot to send alerts. If it's a channel or group, you have to first add the bot in the respective channel / group and allow it to access messages in the permissions settings.
After opening your desired channel / group chatbox, copy the chat id displayed in the url bar.
The id is entire integer string including the preceding-
e.g:-1234567890
- Paste the chat id in the
secret.py
file in front ofchat
variable after-100
.
e.g:chat='-1001234567890'
You can add multiple chat id variables if you want the bot to send alerts in multiple groups / channels.
- Paste the chat id in the
-
Open the
main.py
file and add the pincode(s) for which you want alerts in thepincodes
list on line number9
. -
Save the file. Execute the file using command
python3 main.py
to check if it's working as desired. -
Now, set up a cronjob for this script. A cronjob will execute this script at your desired schedule.
- On linux, open a terminal and execute following command:
crontab -e
- If this is your first time using cron, it'll ask for an editor to choose. Select nano by typing
1
in the cli and press enter / return. - At the end of the file, paste the following line with path to your script:
0 19 * * * <path to your python file>
This line will execute the script daily at 07:00 p.m. - You can customise this according to your need and convenience. Crontab guru is a great place to play around with cron commands.
- Press
Ctrl+X
and pressEnter / return
to save and exit the file.
- On linux, open a terminal and execute following command:
Congratulations! You've successfully set up an automated alert system for cowin appointment slots.