-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (60 loc) · 2.21 KB
/
main.py
File metadata and controls
72 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# < (c) @xditya >
# This was made for personal use.
# If you are using it, kindly keep credits.
from requests import get
import logging
from telethon import TelegramClient, events
from decouple import config
from datetime import datetime
logging.basicConfig(
format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.INFO
)
bottoken = None
# start the bot
logging.info("Starting...")
apiid = 6
apihash = "eb06d4abfb49dc3eeb1aeb98ae0f581e"
try:
bottoken = config("BOT_TOKEN")
auth = [int(x) for x in config("AUTH").split()]
pincode = config("PIN_CODE")
age = int(config("AGE"))
except:
logging.warning("Environment vars are missing! Kindly recheck.")
logging.info("Bot is quiting...")
exit()
try:
bot = (TelegramClient(None, apiid, apihash).start(bot_token=bottoken)).start()
except Exception as e:
logging.warning(f"ERROR!\n{str(e)}")
logging.info("Bot is quiting...")
exit()
logging.info("\n\nStarting to search for Cowin vaccine slots!\n(c) @xditya")
async def processes(): # sourcery no-metrics
async with bot:
msg = ""
for user in auth:
await bot.send_message(user, "Bot Started.")
today = datetime.today().strftime("%d-%m-%Y")
base_url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPin?pincode={}&date={}".format(
pincode, today
)
res = get(base_url)
if res.status_code == 200:
json = res.json()
if json["sessions"]:
for i in json["sessions"]:
if (
i["min_age_limit"] >= age
and i["available_capacity"] > 0
):
msg += f"**Centre**: {i['name']}\n"
msg += f"**Block**: {i['block_name']}\n"
msg += f"**Price**: {i['fee_type']}\n"
msg += f"**Availablity**: {i['available_capacity']}\n"
if i["vaccine"] != "":
msg += f"**Vaccine type**: {i['vaccine']}\n\n"
if msg != "":
for user in auth:
await bot.send_message(user, msg)
bot.loop.run_until_complete(processes())