Skip to content

Instantly share code, notes, and snippets.

@athul
Created May 1, 2021 16:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save athul/3eb40170d2deda922331e6e99039a91b to your computer and use it in GitHub Desktop.
Save athul/3eb40170d2deda922331e6e99039a91b to your computer and use it in GitHub Desktop.

Okay so, this is a telegram bot which sends you a message every 6 hours about vaccine availability in your district.

How to use it?

Edit the source file main.py with some stuff

  • Telegram Bot Token, get it talking to Botfather bot. Line 9

Check this one for explained stuffs

  • Telegram chat id, line 10
  • District code for Cowin API, line 22 check table below for district code
Code District
301 Alappuzha
307 Ernakulam
306 Idukki
297 Kannur
295 Kasaragod
298 Kollam
304 Kottayam
305 Kozhikode
302 Malappuram
308 Palakkad
300 Pathanamthitta
296 Thiruvananthapuram
303 Thrissur
299 Wayanad

Running this

You can use https://deta.sh 's Micros to run this script. You might wanna make an account there and install it's CLI. Then run

  • deta login
  • deta new
  • deta cron set "6 hours"

Mostly that's all

import requests
import pytz
from datetime import date,datetime
from deta import App
app = App()
def sendTGMessage(message:str)->None:
url = f'https://api.telegram.org/bot<Bot token insert here>/sendMessage'
msg_data = {'chat_id':"<Swantham Code kandupidkk>",'text':message,"parse_mode":"Markdown"}
resp = requests.post(url, msg_data).json()
print("Message Not Send" if resp['ok'] is False else "👉 Message Sent")
@app.lib.cron()
def getCowinData(event):
tz = pytz.timezone("Asia/Calcutta")
time= datetime.now(tz).strftime('%H:%M:%S')
date = date.today().strftime("%d-%m-%Y")
data = requests.get(f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=<ithum mattanam>&date={date}").json()
nos_centers = len(data['centers'])
print(nos_centers)
message = f"No Centers Available in <District Name> \n\nat {time} on {date}" if nos_centers<=0 else f"{nos_centers} Available in <District Name> on {date} at {time}"
sendTGMessage(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment