mirror of
https://github.com/codingCoffee/cowin-monitor.git
synced 2025-12-11 03:07:02 +00:00
feat: add cowin book appointment
Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
parent
ee66773268
commit
1682ea1dd1
1 changed files with 117 additions and 0 deletions
117
cowin-book-appointment.py
Normal file
117
cowin-book-appointment.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
||||
# FILL THIS
|
||||
access_token = ""
|
||||
beneficiary = "" # can you can get this form decoding the JWT access token at jwt.io
|
||||
# FILL THIS
|
||||
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
'Origin': 'https://selfregistration.cowin.gov.in',
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'DNT': '1',
|
||||
'Connection': 'keep-alive',
|
||||
'Referer': 'https://selfregistration.cowin.gov.in/',
|
||||
'Sec-GPC': '1',
|
||||
'TE': 'Trailers',
|
||||
}
|
||||
|
||||
params = (
|
||||
('district_id', '395'), # 395 is Mumbai
|
||||
('date', '06-05-2021'), # todays date
|
||||
)
|
||||
|
||||
response = requests.get('https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict', headers=headers, params=params)
|
||||
|
||||
|
||||
# incase you want to book a certain hospital
|
||||
required_hospital = 'seven hills'.lower()
|
||||
|
||||
center_id = ''
|
||||
session_id = ''
|
||||
slot = ''
|
||||
|
||||
if response.ok:
|
||||
print('Sessions available')
|
||||
resp_json = response.json()
|
||||
# pprint(resp_json)
|
||||
for center in resp_json.get('centers'):
|
||||
for session in center.get('sessions'):
|
||||
if session.get('available_capacity') > 0 and session.get('min_age_limit') == 18:
|
||||
print(center)
|
||||
if required_hospital in center.get('name').lower():
|
||||
print(center)
|
||||
print(f"Booking slot in {center.get('name')}")
|
||||
center_id = center.get('center_id')
|
||||
session_id = session.get('session_id')
|
||||
slot = session.get('slots')[0]
|
||||
break
|
||||
else:
|
||||
print("Available Non Matching Center")
|
||||
print(center)
|
||||
else: # crutial else to ensure you're not blocked
|
||||
print("Response Failed")
|
||||
print(response.reason)
|
||||
print(response.text)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0',
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
'Authorization': f'Bearer {access_token}',
|
||||
'Content-Type': 'application/json',
|
||||
'Origin': 'https://selfregistration.cowin.gov.in',
|
||||
'DNT': '1',
|
||||
'Connection': 'keep-alive',
|
||||
'Referer': 'https://selfregistration.cowin.gov.in/',
|
||||
'Sec-GPC': '1',
|
||||
'TE': 'Trailers',
|
||||
}
|
||||
|
||||
print('Center ID: {}'.format(center_id))
|
||||
print(session_id)
|
||||
print(slot)
|
||||
|
||||
# sample_data = '{"center_id":561800,"session_id":"50bceff2-51b0-4c4e-b6c4-af02ccf89c34","beneficiaries":["xxxxxxxxxxxxxx"],"slot":"09:00AM-11:00AM","dose":1}'
|
||||
custom_data = {
|
||||
"center_id": center_id,
|
||||
"session_id": session_id,
|
||||
"beneficiaries":[f"{beneficiary}"],
|
||||
"slot": slot,
|
||||
"dose":1
|
||||
}
|
||||
custom_data = json.dumps(custom_data)
|
||||
custom_data = custom_data.replace(' ', '')
|
||||
|
||||
# print(data)
|
||||
print(custom_data)
|
||||
|
||||
|
||||
if center_id != '':
|
||||
print("Sending POST request to book session")
|
||||
response = requests.post('https://cdn-api.co-vin.in/api/v2/appointment/schedule', headers=headers, data=custom_data)
|
||||
|
||||
if response.ok:
|
||||
print("Response Succeeded")
|
||||
print(response)
|
||||
try:
|
||||
print(response.json())
|
||||
except:
|
||||
pass
|
||||
else: # crutial else to ensure you're not blocked
|
||||
print("Response Failed")
|
||||
print(response.reason)
|
||||
print(response.text)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
Loading…
Reference in a new issue