Skip to content

Instantly share code, notes, and snippets.

@debarko
Last active June 3, 2021 08:07
Show Gist options
  • Save debarko/45995919e2dc13d741b75215d393800d to your computer and use it in GitHub Desktop.
Save debarko/45995919e2dc13d741b75215d393800d 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 District IDs
// Change the districts to your needs as per your city
// Change the dateArr to add your convinent set of dates
// For further update do checkout http://twitter.com/debarko/
// 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 10 seconds and check for availability of slots.
// Config
// ------
var districts = [265, 276, 294, 277, 290, 266, 288, 292];
var dateArr = ["30-05-2021", "31-05-2021", "01-06-2021"];
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 fetchByDistrict() {
console.log("Check: ", trialCounter++);
for (i=0;i < districts.length; i++) {
for (j=0; j < dateArr.length; j++) {
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id="+districts[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("Trying Booking for", a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity);
var audio = new Audio('https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3');
audio.play();
}
}
}
}
}
await sleepNow(30000);
fetchByDistrict();
}
console.log('Script Initialising');
fetchByDistrict();
// 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
// Change the dateArr to add your convinent set of dates
// For further update do checkout http://twitter.com/debarko/
// 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 10 seconds and check for availability of slots.
// Config
// ------
var pincodes = ["560076", "560020", "560078", "560001", "560017", "560103", "560027", "560064", "560071", "560084", "560035", "560066", "560048"];
var dateArr = ["30-05-2021", "31-05-2021", "01-06-2021"];
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("Trying Booking for", a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity);
var audio = new Audio('https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3');
audio.play();
}
}
}
}
}
await sleepNow(30000);
fetchByPincode();
}
console.log('Script Initialising');
fetchByPincode();
@varun160490
Copy link

I have create 100% working and faster script to AUTOMATICALLY BOOK CoWin VACCINE SLOT WITH CAPTCHA LOGIC.

https://gist.github.com/varun160490/61f96b54a9b59f44b6e4468751faa525

Please Check...

Thank you @debarko for the script!
It works as expected and I was able to see requests in Network tab. But, I faced 2 issues:

  1. The Audio didn't work/play when the slot became available (Network stream was showing 304 as return code). But when I tried declaring audio variable manually and then executed audio.play() I was able to hear the beep sound. (For clarification, I was doing something else on the same laptop (not gaming or anything audio related) and so, I expected the script to be running in background and beep when slot becomes available but I didn't hear any beep)
  2. Is there a way to refresh the table on UI ? Asking this because, I missed the first 2 hospitals because the audio didn't got played (idk why), but for the next 2 hospitals, I was tracking 304 response on the Network stream and was also able to see logs on developer console regarding availability going down from 150 to 120, 74, etc..... But the website wasn't even updating the details.... just "NA" and when it started showing availability... the number was around 15 and I missed the booking slot.

Please, I am not blaming you in any way. Just wanted to share my experience. Thank you soo much for creating this simple javascript /

If I could get solutions for these from anyone, That would be extremely helpful.

Relax guys They have introduced captcha now Autobooking will never work

I

@debarko
Copy link
Author

debarko commented May 12, 2021

Anyone with react native experience here? Wanted to make an app. I can help with the whole integration but need help in building it fast. Hope the internet helps..

Reach out to me on http://twitter.com/debarko/. DMs are open

@rajeevriitm
Copy link

I have actually built an app and backend. But don't know any free server providers in India. Any idea on that which doesn't require a credit card?

@debarko
Copy link
Author

debarko commented May 12, 2021

AWS has a year long free tier account. LINK Not sure whether it needs credit card or not

@rajeevriitm
Copy link

Does aws provides servers in India for free tier?

@achadaga
Copy link

Does aws provides servers in India for free tier?

Let me know servers providers in India. Even if it is not paid,I will pay it and provide the server to you. How about dreamhost? Do they provide servers in India ? I have an account,can provide paid server. Let me know

@achadaga
Copy link

Does aws provides servers in India for free tier?

Let me know servers providers in India. Even if it is not paid,I will pay it and provide the server to you. How about dreamhost? Do they provide servers in India ? I have an account,can provide paid server. Let me know

I do have aws free tier available. Don't know if the freetier servers are good enough in terms of RAM and speed.

@falaksangani
Copy link

Guys, found this today it works well gives alert on whatsapp and telegram.
https://github.com/veenaypatil/Vaccine-Slot-Info

@achadaga
Copy link

Guys, found this today it works well gives alert on whatsapp and telegram.
https://github.com/veenaypatil/Vaccine-Slot-Info

Thank you for this. Was looking for something in python.

@code-ghalib
Copy link

Great going guys! Imagine if everyone runs this on their computers - I'm sure the cowin servers will be able to scale to handle 1 billion people querying it every 10 seconds! This is brilliant - this is just what we need! Citizens executing a denial of service attack on their own government's already inept attempts at dealing with a global pandemic!

@Pulkit251
Copy link

how to get the availability of a specific vaccine

@singhrajtomar
Copy link

Is there any way to specify vaccine type in the code? I got first dose of COVAXIN and it's time for my second dose. I need the console to look for slots of COVAXIN only

@sakets96
Copy link

how to get the availability of a specific vaccine

why do you want any specific vaccine

@singhrajtomar
Copy link

how to get the availability of a specific vaccine

why do you want any specific vaccine

I already got the first dose of COVAXIN. My second dose is due. That's why i need it

@sidpagariya
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

@imdsrs
Copy link

imdsrs commented May 21, 2021

how to get the availability of a specific vaccine

why do you want any specific vaccine

I already got the first dose of COVAXIN. My second dose is due. That's why i need it

Replace line #51, in the original code, with following:
if (a.centers[c].sessions[s].vaccine === "COVAXIN" && a.centers[c].sessions[s].available_capacity_dose2 > 0 && a.centers[c].sessions[s].min_age_limit < 45) {

@newreddy
Copy link

I have created 100% working and faster script to automatically BOOK CoWin VACCINE SLOT.

AUTOMATICALLY BOOK VACCINE SLOT SCRIPT

Please Check...

is it working? did any one tried ? please let me know.
I want to try

@Pulkit251
Copy link

how to get the availability of a specific vaccine

why do you want any specific vaccine

I already got the first dose of COVAXIN. My second dose is due. That's why i need it

Replace line #51, in the original code, with following:
if (a.centers[c].sessions[s].vaccine === "COVAXIN" && a.centers[c].sessions[s].available_capacity_dose2 > 0 && a.centers[c].sessions[s].min_age_limit < 45) {

I implemented it but thanks for the help, much appreciated..

@newreddy
Copy link

how to get the availability of a specific vaccine

why do you want any specific vaccine

I already got the first dose of COVAXIN. My second dose is due. That's why i need it

Replace line #51, in the original code, with following:
if (a.centers[c].sessions[s].vaccine === "COVAXIN" && a.centers[c].sessions[s].available_capacity_dose2 > 0 && a.centers[c].sessions[s].min_age_limit < 45) {

I implemented it but thanks for the help, much appreciated..

could you let me know final script ? is it auto booking?

@newreddy
Copy link

I have created 100% working and faster script to automatically BOOK CoWin VACCINE SLOT.

AUTOMATICALLY BOOK VACCINE SLOT SCRIPT

Please Check...

polyfills-es2015.15fb4198457dfa37b8c6.js:1 Access to XMLHttpRequest at 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=294&date=23-05-2021' from origin 'https://selfregistration.cowin.gov.in' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
(anonymous) @ polyfills-es2015.15fb4198457dfa37b8c6.js:1
D.s. @ polyfills-es2015.15fb4198457dfa37b8c6.js:1
httpGet @ VM54:60
fetchByDistrict @ VM54:78
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
async function (async)
fetchByDistrict @ VM54:106
fetchByDistrict @ VM54:107
polyfills-es2015.15fb4198457dfa37b8c6.js:1 GET https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=294&date=23-05-2021 net::ERR_FAILED

@newreddy
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

@sidpagariya
Copy link

sidpagariya commented May 22, 2021

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

Hi there @newreddy, those are for which centers you want to explicitly want to only book slots from, and those can be found by going to the url similar to: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=DISTRICT_NUMBER&date=DD-MM-YYYY where DISTRICT_NUMBER is the number you determine following steps in the README and the date formatted per the format shown in the aforementioned url. In there, you'll see each center in that district, and you can whitelist specific ones, or just leave that environment variable blank to book slots from any center

@newreddy
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

Hi there @newreddy, those are for which centers you want to explicitly want to only book slots from, and those can be found by going to the url similar to: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=DISTRICT_NUMBER&date=DD-MM-YYYY where DISTRICT_NUMBER is the number you determine following steps in the README and the date formatted per the format shown in the aforementioned url. In there, you'll see each center in that district, and you can whitelist specific ones, or just leave that environment variable blank to book slots from any center

Hi,
Thanks for response.

one small doubt. I am looking only for COVAXIN but log keep on printing but shows COVISHILED only.

@sidpagariya
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

Hi there @newreddy, those are for which centers you want to explicitly want to only book slots from, and those can be found by going to the url similar to: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=DISTRICT_NUMBER&date=DD-MM-YYYY where DISTRICT_NUMBER is the number you determine following steps in the README and the date formatted per the format shown in the aforementioned url. In there, you'll see each center in that district, and you can whitelist specific ones, or just leave that environment variable blank to book slots from any center

Hi,
Thanks for response.

one small doubt. I am looking only for COVAXIN but log keep on printing but shows COVISHILED only.

Yeah so that means there are no slots currently available for COVAXIN appointments. If you provided COVAXIN in vaccine type and are trying to book then when those slots open it’ll prompt you for captcha and register immediately!

@newreddy
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

Hi there @newreddy, those are for which centers you want to explicitly want to only book slots from, and those can be found by going to the url similar to: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=DISTRICT_NUMBER&date=DD-MM-YYYY where DISTRICT_NUMBER is the number you determine following steps in the README and the date formatted per the format shown in the aforementioned url. In there, you'll see each center in that district, and you can whitelist specific ones, or just leave that environment variable blank to book slots from any center

Hi,
Thanks for response.
one small doubt. I am looking only for COVAXIN but log keep on printing but shows COVISHILED only.

Yeah so that means there are no slots currently available for COVAXIN appointments. If you provided COVAXIN in vaccine type and are trying to book then when those slots open it’ll prompt you for captcha and register immediately!

Thanks,

but problem is every 5min need to enter OTP and captcha for final booking. we need to be in front of the system all the times

@newreddy
Copy link

Hey y'all, just saw this! I actually have a really comprehensive script with just a few setup instructions you can immediately run through and setup, with completely functional auto booking, just that you need OTP and captchas entered manually, but it still is really handy!
https://github.com/sidpagariya/cowin-notifier
Arogya Setu and Umang reverse-engineered endpoints without captcha also in the works so all you really need is the OTP, which can also be automated from your phone using IFTTT!

Hi,
what is cowin_whitelist_center_ids ? is it pincode of center ?

Hi there @newreddy, those are for which centers you want to explicitly want to only book slots from, and those can be found by going to the url similar to: https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=DISTRICT_NUMBER&date=DD-MM-YYYY where DISTRICT_NUMBER is the number you determine following steps in the README and the date formatted per the format shown in the aforementioned url. In there, you'll see each center in that district, and you can whitelist specific ones, or just leave that environment variable blank to book slots from any center

Hi,
Thanks for response.
one small doubt. I am looking only for COVAXIN but log keep on printing but shows COVISHILED only.

Yeah so that means there are no slots currently available for COVAXIN appointments. If you provided COVAXIN in vaccine type and are trying to book then when those slots open it’ll prompt you for captcha and register immediately!

Hi sidpagariya,
Thanks for reply. I got slot but not able to see captcha. I am running the script in cmd prompt.
could you please let me know how I can see proper captcha ?

@sidpagariya
Copy link

sidpagariya commented May 23, 2021

Hi sidpagariya,
Thanks for reply. I got slot but not able to see captcha. I am running the script in cmd prompt.
could you please let me know how I can see proper captcha ?

Hello @newreddy, you can actually pull from the repository as I have now automated the captcha portion, thanks to https://github.com/sushrut111/cowin-automation-extn, especially @ayushchd
All you need to worry about is getting OTP now, and I will be pushing up some steps in the README to also automate the OTPs

@newreddy
Copy link

Hi sidpagariya,
Thanks for reply. I got slot but not able to see captcha. I am running the script in cmd prompt.
could you please let me know how I can see proper captcha ?

Hello @newreddy, you can actually pull from the repository as I have now automated the captcha portion, thanks to https://github.com/sushrut111/cowin-automation-extn, especially @ayushchd
All you need to worry about is getting OTP now, and I will be pushing up some steps in the README to also automate the OTPs

it has some issue, if enable auto refresh some exception coming and not able to relogin.

@sidpagariya
Copy link

it has some issue, if enable auto refresh some exception coming and not able to relogin.

Let's move this over to https://github.com/sidpagariya/cowin-notifier/issues/new/choose and please describe your issue so we can get it resolved asap! :)

@shantanuroy4u
Copy link

I have create 100% working and faster script to get CoWin vaccine slot availability alerts.

Cowin Vaccine Alert Script

Please Check...

Thank varun,It is working as nicely.I took the vaccine today
Only we could have use pincode ,it would be more user friendlier

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