├── .gitignore ├── .env.sample ├── requirements.txt ├── Dockerfile ├── ReadMe.md └── main.py /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | BOT_TOKEN= 2 | AUTH= 3 | PIN_CODE= 4 | AGE= -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | telethon 2 | requests 3 | python-decouple -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9-alpine 2 | 3 | COPY . /app 4 | WORKDIR /app 5 | 6 | RUN pip3 install -r requirements.txt 7 | 8 | CMD ["python3", "main.py"] 9 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # Cowin Notifier Bot 2 | 3 | ## Variables 4 | `BOT_TOKEN` - Telegram bot token. 5 | `AUTH` - Telegram user id(s) split by space. 6 | `PIN_CODE` - Locality pin code. 7 | `AGE` - Maximum age limit. -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # < (c) @xditya > 2 | # This was made for personal use. 3 | # If you are using it, kindly keep credits. 4 | 5 | from requests import get 6 | import logging 7 | from telethon import TelegramClient, events 8 | from decouple import config 9 | from datetime import datetime 10 | 11 | logging.basicConfig( 12 | format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.INFO 13 | ) 14 | 15 | bottoken = None 16 | 17 | # start the bot 18 | logging.info("Starting...") 19 | apiid = 6 20 | apihash = "eb06d4abfb49dc3eeb1aeb98ae0f581e" 21 | 22 | try: 23 | bottoken = config("BOT_TOKEN") 24 | auth = [int(x) for x in config("AUTH").split()] 25 | pincode = config("PIN_CODE") 26 | age = int(config("AGE")) 27 | except: 28 | logging.warning("Environment vars are missing! Kindly recheck.") 29 | logging.info("Bot is quiting...") 30 | exit() 31 | 32 | try: 33 | bot = (TelegramClient(None, apiid, apihash).start(bot_token=bottoken)).start() 34 | except Exception as e: 35 | logging.warning(f"ERROR!\n{str(e)}") 36 | logging.info("Bot is quiting...") 37 | exit() 38 | 39 | 40 | logging.info("\n\nStarting to search for Cowin vaccine slots!\n(c) @xditya") 41 | 42 | 43 | async def processes(): # sourcery no-metrics 44 | async with bot: 45 | msg = "" 46 | for user in auth: 47 | await bot.send_message(user, "Bot Started.") 48 | today = datetime.today().strftime("%d-%m-%Y") 49 | base_url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?pincode={}&date={}".format( 50 | pincode, today 51 | ) 52 | res = get(base_url) 53 | if res.status_code == 200: 54 | json = res.json() 55 | if json["sessions"]: 56 | for i in json["sessions"]: 57 | if ( 58 | i["min_age_limit"] >= age 59 | and i["available_capacity"] > 0 60 | ): 61 | msg += f"**Centre**: {i['name']}\n" 62 | msg += f"**Block**: {i['block_name']}\n" 63 | msg += f"**Price**: {i['fee_type']}\n" 64 | msg += f"**Availablity**: {i['available_capacity']}\n" 65 | if i["vaccine"] != "": 66 | msg += f"**Vaccine type**: {i['vaccine']}\n\n" 67 | if msg != "": 68 | for user in auth: 69 | await bot.send_message(user, msg) 70 | 71 | 72 | bot.loop.run_until_complete(processes()) 73 | --------------------------------------------------------------------------------