Last active
May 18, 2021 06:53
-
-
Save vinodnimbalkar/594123f98204b26c696324e66bd64fba 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/
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 script inspired by -> https://gist.github.com/debarko/45995919e2dc13d741b75215d393800d | |
Thanks to Debarko De. | |
It might be not working on an older browser. | |
Change the pincodes to your needs as per your city. | |
How To setup Video -> https://www.youtube.com/watch?v=3_N5FFegtI4 | |
Steps to use | |
1. Update Pincode eg. ['110001', '110002'] and update age e.g 25 | |
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.js | |
7. Press Enter | |
It will run every 30 seconds and check for availability of slots. | |
*/ | |
const personDetails = { | |
pincodes: ['110002', '110003'], // Please insert your pincodes | |
age: '25', // Please change your age | |
}; | |
const date = new Date().toLocaleDateString().replace(/\//g, '-'); | |
let trialCounter = 1; | |
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | |
async function fetchByPincode({ pincodes, age }) { | |
const THIRTY_SECONDS = '30000'; | |
console.log('Check: ', trialCounter++); | |
pincodes.forEach(async (pincode) => { | |
const url = `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=${pincode}&date=${date}`; | |
try { | |
const response = await fetch(url); | |
if (response.status === 401) return; | |
const data = await response.json(); | |
if (data !== undefined && data.centers.length !== 0) { | |
for (let center in data.centers) { | |
for (let session in data.centers[center].sessions) { | |
if ( | |
data.centers[center].sessions[session].min_age_limit < age && | |
data.centers[center].sessions[session].available_capacity > 0 | |
) { | |
console.log( | |
`Slot available, Book Now.. \nPincode : ${data.centers[center].pincode}\nCenter : ${data.centers[center].name}\nSlot Availabe : ${data.centers[center].sessions[session].available_capacity}` | |
); | |
let audio = new Audio( | |
'https://suonoelettronico.com/waves22/sirena_ambulanza.mp3' | |
); | |
audio.play(); | |
} | |
} | |
} | |
} | |
} catch (e) { | |
return; | |
} | |
}); | |
await sleep(THIRTY_SECONDS); | |
fetchByPincode(personDetails); | |
} | |
fetchByPincode(personDetails); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment