-
Notifications
You must be signed in to change notification settings - Fork 0
/
cowin_api.py
48 lines (38 loc) · 1.42 KB
/
cowin_api.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
import requests
import json
import datetime
import csv
import os
from twilio.rest import Client
today = datetime.date.today().strftime("%d-%m-%Y")
csv_file = open('cowin_slots.csv','a+',newline="")
csv_writer = csv.writer(csv_file)
# csv_writer.writerow(['Name','pincode','Vaccine','Availability'])
pincode = input ("Enter your pincode : ")
number = input("Enter your mobile number : ")
r = requests.get('https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=' + pincode +'&date='+today)
CoData = json.loads(r.text)
centers = CoData['centers']
for i in centers:
# print(i)
name = i['name']
print(name)
s = i['sessions'][0]
# print(s)
capacity = s['available_capacity']
vaccine = s['vaccine']
print(f"Vaccine : {vaccine}")
print(f"Available slots : {capacity} ")
print(" ")
csv_writer.writerow([name,pincode,vaccine,capacity])
if capacity > 0:
account_sid = 'Enter your api id here'
auth_token = 'Enter your auth token here'
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body=f"Hey, {capacity} {vaccine} vaccine slots are availabe at {name}.",
from_='Enter the number from the api',
to=f'{number}'
)
csv_file.close()