-
-
Save varun160490/1b325874ab4198d48440e9944a9d95a9 to your computer and use it in GitHub Desktop.
// 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(); |
@prasannamandhalapun,
Thanks.. I have already mentioned in my first comment how to find a district id. Anyway, the district id for Hyderabad is 581.
Is the output supposed to show this:
Check: 1
polyfills.8c151b8375e767ff858f.js:1 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
(anonymous) @ polyfills.8c151b8375e767ff858f.js:1
s. @ polyfills.8c151b8375e767ff858f.js:1
httpGet @ VM501:34
fetchByDistrict @ VM501:44
(anonymous) @ VM501:66
Promise {}
VM501:40 Check: 2
VM501:40 Check: 3
VM501:40 Check: 4
VM501:40 Check: 5
VM501:40 Check: 6
VM501:40 Check: 7
VM501:40 Check: 8
VM501:40 Check: 9
VM501:40 Check: 10
VM501:40 Check: 11
VM501:40 Check: 12
VM501:40 Check: 13
VM501:40 Check: 14
VM501:40 Check: 15
VM501:40 Check: 16
VM501:40 Check: 17
VM501:40 Check: 18
VM501:40 Check: 19
VM501:40 Check: 20
VM501:40 Check: 21
VM501:40 Check: 22
VM501:40 Check: 23
VM501:40 Check: 24
Is the output supposed to show this:
Check: 1
polyfills.8c151b8375e767ff858f.js:1 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
(anonymous) @ polyfills.8c151b8375e767ff858f.js:1
s. @ polyfills.8c151b8375e767ff858f.js:1
httpGet @ VM501:34
fetchByDistrict @ VM501:44
(anonymous) @ VM501:66
Promise {}
VM501:40 Check: 2
VM501:40 Check: 3
@jaweedt, this is correct. It is checking for slot every 3 seconds and will alert you as soon as the slot opens up...
Those looking for 2nd dose can replace "session.available_capacity" on line 55 and 56 with "session.available_capacity_dose2"
Hi Varun...., Thanks for the amazing code . I have small query where we can get this district codes like you mentioned as 363 in your code as per the city. I am just trying it to find out for Hyderabad