Skip to content

Instantly share code, notes, and snippets.

@akhilerm
Created May 27, 2021 17:19
Show Gist options
  • Save akhilerm/365dd94ea57c11f49dbbd4c13e8490cd to your computer and use it in GitHub Desktop.
Save akhilerm/365dd94ea57c11f49dbbd4c13e8490cd to your computer and use it in GitHub Desktop.
cowin slot
import os
import requests
import json
import datetime
import time
import sys
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"}
def sound():
for _ in range(10):
os.system('play -nq -t alsa synth 1 sine 440')
time.sleep(1)
def main(argv):
district_id = argv[1]
age_limit = int(argv[2])
while(1):
d = datetime.date.today().strftime("%d-%m-%y")
param = {"district_id":district_id,"date":d}
resp = requests.get(url, params=param, headers=headers)
try:
data = resp.json()
except Exception as e:
print('JSON Decode error', e)
continue
for center in data["centers"]:
for session in center["sessions"]:
if(int(session["available_capacity_dose1"])>0 and int(session["min_age_limit"])==age_limit):
print(center['address'])
print('Dose1 available', session["available_capacity_dose1"])
sound()
time.sleep(10)
if __name__ == "__main__":
main(sys.argv)
@akhilerm
Copy link
Author

akhilerm commented May 27, 2021

This script checks only for dose1 availability, and plays a sound using sox.

Install sox using

sudo apt install sox

Run

python cowin.py <district ID> <18/45>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment