Skip to content

Instantly share code, notes, and snippets.

@Technowise
Forked from debarko/cowin_schedule_district_wise.js
Last active May 17, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Technowise/056950c345604e6a649f49ee95ac5127 to your computer and use it in GitHub Desktop.
Save Technowise/056950c345604e6a649f49ee95ac5127 to your computer and use it in GitHub Desktop.
Get an update on console as soon as a slot opens up in https://selfregistration.cowin.gov.in/ . Login to the website and then run this script on Console.
// This script will alert you whenever some slot opens up on the given date within the given pincodes
// Change the pincodes to your needs as per your city
// Optionally: the next_days variable can be set to number of days it has to check. (If you set to 3, will check for next three days.)
// How To setup Video -> https://www.youtube.com/watch?v=3_N5FFegtI4
// Steps to use
// 1. Update Config
// 2. Login to https://selfregistration.cowin.gov.in/
// 3. Rigt Click on the website
// 4. Click on Inspect
// 5. Open the Console Tab on your Inspect window
// 6. Copy paste the contents of this entire file - cowin_schedule_v2.js
// 7. Press Enter
// It will run every 15 seconds and check for availability of slots.
// Config
// ------
var pincodes = ["560078", "560076", "560020", "560011"];
var next_days = 3;
var date = new Date();
var dateArr = [];
for ( x=0; x < next_days; x++)
{
date.setDate(date.getDate() + 1);//Start from tomorrow (skip today)
var d = date.getDate();
var m = date.getMonth() + 1;
var y = date.getFullYear();
var dateString = (d <= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y;
dateArr.push(dateString);
}
var trialCounter = 1;
const sleepNow = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
async function fetchByPincode() {
console.log("Check: ", trialCounter++);
for (i=0;i < pincodes.length; i++) {
for (j=0; j < dateArr.length; j++) {
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode="+pincodes[i]+"&date="+dateArr[j];
await sleepNow(1100);
a = httpGet(url);
try {
a = JSON.parse(a)
} catch(e) {
continue;
}
for (c in a.centers) {
for (s in a.centers[c].sessions) {
if (a.centers[c].sessions[s].min_age_limit < 45 && a.centers[c].sessions[s].available_capacity > 0) {
console.log("Try Booking for: ", a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity);
console.log("Date: "+dateArr[j])
var audio = new Audio('https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3');
audio.play();
}
else {
console.log("no slots available for "+pincodes[i]+" on "+dateArr[j]);
}
}
}
}
}
await sleepNow(15000);
fetchByPincode();
}
console.log('Script Initialising');
fetchByPincode();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment