Skip to content

Instantly share code, notes, and snippets.

@sanketplus
Last active May 3, 2021 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanketplus/c62905d234c323a8abdb6110f600bd09 to your computer and use it in GitHub Desktop.
Save sanketplus/c62905d234c323a8abdb6110f600bd09 to your computer and use it in GitHub Desktop.
`pip install twilio`
import os
import datetime
import requests
import time
from twilio.rest import Client
account_sid = <SID>
auth_token = <AUTH>
PIN = <PINCODE>
MY_PHONE = <REGISTERED ON TWILIO>
MY_TWILIO_NUMBER = <TWILIO NUMBER>
client = Client(account_sid, auth_token)
URL = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin"
def get_appointments(date):
params = {"date": date, "pincode": PIN}
resp = requests.get(URL, params=params)
data = resp.json()
centers = data["centers"]
available_centers = [c for c in centers for s in c["sessions"] if s["available_capacity"] > 0]
return available_centers
def call():
call = client.calls.create(
twiml='<Response><Say>VACCINE IS AVAILABLE, RUN!</Say></Response>',
to=MY_PHONE,
from_=MY_TWILIO_NUMBER
)
print(call.sid)
def main():
while True:
try:
today = datetime.datetime.today()
tom = (today + datetime.timedelta(days=0)).strftime("%d-%m-%Y") # EDITED, UI seems to be seding today's date for next. 7 days data
tom1 = (today + datetime.timedelta(days=1)).strftime("%d-%m-%Y")
appts = []
appts.extend(get_appointments(tom))
appts.extend(get_appointments(tom1))
print(appts)
if appts:
call()
except Exception as e:
print("Exception:", e)
time.sleep(50)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment