forked from nuarc/cowin_availability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_cowin.py
41 lines (32 loc) · 1.36 KB
/
call_cowin.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
import json
from datetime import date
import pymsteams
import requests
today = date.today()
d1 = today.strftime("%d-%m-%Y")
district_ids = ["143", "146"] # north west delhi, north delhi
webhook_url = "" # USE WEBHOOK, here i am using MS teams
available_centers = []
for id in district_ids:
query = {'date': d1, 'district_id': id}
headers = {"User-Agent": "PostmanRuntime/7.26.10"}
url = f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict"
print("query =", query)
response = requests.get(url, params=query, headers=headers)
centers = response.json()["centers"]
for center in centers:
name = center["name"]
address = center["address"]
pincode = center["pincode"]
district_name = center["district_name"]
for session in center["sessions"]:
if session["min_age_limit"] == 18 and session["available_capacity"] > 0:
c = {'name': name, 'address': address, 'pincode': pincode, 'district_name': district_name,
"capacity": session["available_capacity"], "date": session["date"]}
available_centers.append(c)
break
if len(available_centers) > 0:
print(available_centers)
myTeamsMessage = pymsteams.connectorcard(webhook_url)
myTeamsMessage.text(json.dumps(available_centers))
myTeamsMessage.send()