-
Notifications
You must be signed in to change notification settings - Fork 0
/
cowid_bot.py
63 lines (45 loc) · 2.31 KB
/
cowid_bot.py
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
import requests
from datetime import datetime
base_cowin_url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict"
api_url_telegram = "https://api.telegram.org/botenteryourbotidhere/sendMessage?chat_id=@__groupid__&text="
now = datetime.now()
today_date = now.strftime("%d-%m-%Y")
group_id = ""
name_list = []
def fetch_data_from_cowin(district_id):
querry_params = "?district_id={}&date={}".format(district_id, today_date)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36'}
final_url = base_cowin_url + querry_params
response = requests.get(final_url, headers=headers)
extract_availability_data(response)
def extract_availability_data(response):
response_json = response.json()
for center in response_json["centers"]:
for session in center["sessions"]:
if session["available_capacity"] > 0 and session["min_age_limit"] == 18: # for 18+ vaccine
if int(center["center_id"]) not in name_list:
message = "Vaccination centers for {}+ age group: \n{} ({})- Pin: {}. \nVaccine: {} \nFee Type: {} \nTotal {} slots are available on {} \n(Dose 1: {}, Dose 2: {})".format(
session["min_age_limit"],
center["name"],
center["block_name"],
center["pincode"],
session["vaccine"],
center["fee_type"],
session["available_capacity"],
session["date"],
session["available_capacity_dose1"],
session["available_capacity_dose2"]
)
name_list.append(int(center["center_id"]))
print(name_list)
message = message + "\n\nCoWin: https://selfregistration.cowin.gov.in"
send_message_telegram(message)
def send_message_telegram(message):
final_telegram_url = api_url_telegram.replace("__groupid__", group_id)
final_telegram_url = final_telegram_url + message
response = requests.get(final_telegram_url)
print(response)
while(True):
fetch_data_from_cowin(296)
# 296 is of Trivandrum district