Last active
June 9, 2021 06:07
-
-
Save varun160490/1b325874ab4198d48440e9944a9d95a9 to your computer and use it in GitHub Desktop.
Working script to get vaccine availability alert on console as soon as a slot opens up in https://selfregistration.cowin.gov.in/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This javascript code will alert you whenever some slot opens up on the given date within the given pincodes. | |
// This script will run every 2 seconds and check for availability of slots. | |
// Steps to use | |
// 1. Update pincodes,age,district_id,vaccine & vaccine_date. | |
// 2. Login to https://selfregistration.cowin.gov.in/ | |
// 3. Right Click on the website | |
// 4. Click on Inspect | |
// 5. Switch to the Console Tab on the recently opened Inspect window | |
// 6. Copy paste the contents of this entire file - cowin_vaccination.js | |
// 7. Press Enter | |
var sleepNow = (delay) => new Promise((resolve) => setTimeout(resolve, delay)) | |
var trialCounter = 1; | |
// Change the pincodes as per your city | |
var pincodes = [411001,411028,411057,410506,410501,411027,411017,411006,411033,411035,411041,412115,411044,411011,411027,411026,411001,411038,411018]; | |
// Change the age as per your requirement | |
var age = 18; //45,18 | |
// Change the distric id as per the city you are living in | |
var district_id = 363; | |
// Change the vaccine as per your need. Check comments on how to get distric id. | |
var vaccine = "COVAXIN"; // COVISHIELD,COVAXIN | |
// change the date to the date of slot booking | |
var vaccine_date = "29-05-2021"; | |
// Enter dose = 1 for first dose, dose = 2 for second dose | |
var dose = 1; | |
function httpGet(theUrl) | |
{ | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request | |
xmlHttp.send( null ); | |
return xmlHttp.responseText; | |
} | |
async function fetchByDistrict() { | |
console.log("Check: ", trialCounter++); | |
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id="+district_id+"&date="+vaccine_date; | |
try { | |
centers = JSON.parse(httpGet(url)).centers; | |
} catch(e) { | |
console.log("error"); | |
} | |
for (i in centers) { | |
center = centers[i]; | |
for (j in center.sessions) { | |
session = center.sessions[j]; | |
//console.log(session); | |
var available_capacity = 0; | |
if(dose==1) | |
available_capacity = session.available_capacity_dose1; | |
else if(dose==2) | |
available_capacity = session.available_capacity_dose2; | |
if (session.min_age_limit == age && session.available_capacity > 0 && session.vaccine == vaccine && pincodes.includes(center.pincode)) { | |
console.log("Vaccines available at : ", center.pincode, center.name, session.available_capacity); | |
var audio = new Audio('https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3'); | |
audio.play(); | |
} | |
} | |
} | |
await sleepNow(2000); | |
fetchByDistrict(); | |
} | |
fetchByDistrict(); |
Those looking for 2nd dose can replace "session.available_capacity" on line 55 and 56 with "session.available_capacity_dose2"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jaweedt, this is correct. It is checking for slot every 3 seconds and will alert you as soon as the slot opens up...