Last active
May 12, 2021 18:20
-
-
Save debarko/3073324b2e277a27ff95ca735c38ec57 to your computer and use it in GitHub Desktop.
cowin book backup
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 is WIP (Work in Progress) and this doesn't work, auto booking is still not tested properly. Use the last file cowin_schedule_v2.js | |
// If you want use the 3rd file in the list which will alert you as soon as a slot opens up | |
// This script tries to automatically book a slot from the list of pincodes given. | |
// It will book the first available slot. | |
// You can get the beneficiary ID from your networks tab when the dashboard loads | |
// Please do change the date to which ever day you are searching for. (Works only for a few days in advance) | |
// Config | |
// ------ | |
var pincodes = ["560076", "560062", "560020", "560078", "560001", "560017", "560027", "560064", "560071", "560084"]; | |
var beneficiaries = ["74969837353740"]; | |
var dateSelect = "02-05-2021"; | |
var script = document.createElement('script'); | |
script.src = 'https://code.jquery.com/jquery-3.4.1.min.js'; | |
script.type = 'text/javascript'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
function httpGet(theUrl) | |
{ | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request | |
xmlHttp.send( null ); | |
return xmlHttp.responseText; | |
} | |
function fetchByPincode() { | |
console.log("Fetching By Pin") | |
for (i=0;i < pincodes.length; i++) { | |
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode="+pincodes[i]+"&date="+dateSelect; | |
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 to Book for", a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity); | |
data = { | |
center_id: a.centers[c].center_id, | |
session_id: a.centers[c].sessions[s].session_id, | |
dose: 1, | |
slot: a.centers[c].sessions[s].slots[0], | |
beneficiaries: beneficiaries | |
} | |
upload(data); | |
return; | |
} | |
} | |
} | |
} | |
} | |
function upload(data) { | |
console.log('upload start'); | |
return $.ajax({ | |
type: "POST", | |
url: "https://cdn-api.co-vin.in/api/v2/appointment/schedule", | |
data: data, | |
timeout: 3000, | |
success: function(result) { | |
console.log('Dumping Result Log'); | |
console.log(result); | |
console.log('Booking Success'); | |
clearInterval(timerClock); | |
} | |
}); | |
} | |
var timerClock = setInterval(fetchByPincode, 10000); |
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
// DEPRECATED | |
// Use the v2 script below | |
function httpGet(theUrl) | |
{ | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request | |
xmlHttp.send( null ); | |
return xmlHttp.responseText; | |
} | |
function fetchSlots() { | |
console.log("Fetch Init"); | |
a = httpGet("https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=265&date=01-05-2021") | |
a = JSON.parse(a) | |
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(a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity) | |
} | |
} | |
} | |
} | |
setInterval(fetchSlots, 2000); | |
function fetchByPincode() { | |
console.log("Fetching By Pin") | |
pincodes = ["560076", "560062", "560020", "560078", "560001", "560017", "560027", "560064", "560071", "560084"]; | |
for (i=0;i < pincodes.length; i++) { | |
console.log(pincodes[i]); | |
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode="+pincodes[i]+"&date=01-05-2021"; | |
a = httpGet(url); | |
a = JSON.parse(a) | |
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(a.centers[c].pincode, a.centers[c].name, a.centers[c].sessions[s].available_capacity) | |
} | |
} | |
} | |
} | |
} | |
setInterval(fetchByPincode, 10000); |
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
// DEPRECATED | |
// Use version 3 below this. | |
// 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 dateSelect to your convinent date | |
// 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", "560062", "560020", "560078", "560001", "560017", "560027", "560064", "560071", "560084"]; | |
var dateSelect = "02-05-2021"; | |
function httpGet(theUrl) | |
{ | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request | |
xmlHttp.send( null ); | |
return xmlHttp.responseText; | |
} | |
function fetchByPincode() { | |
console.log("Fetching By Pin") | |
for (i=0;i < pincodes.length; i++) { | |
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode="+pincodes[i]+"&date="+dateSelect; | |
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(); | |
} | |
} | |
} | |
} | |
} | |
setInterval(fetchByPincode, 10000); |
qq:https://cdn-api.co-vin.in/api/v2/appointment/schedule
does this API work without authentication?
@reddivari9 Auto book is not developed. Right now working on a chrome extension for alerting. Once that is done will look into auto book
@abhishek1234321 no it doesn't. This script was written for the scenario that user is logged into self registration website.
thanks for your help and all the work you have done
@sumalya: Auto book doesn't work. I haven't finished it and also not working on it anymore. You can use https://gist.github.com/debarko/45995919e2dc13d741b75215d393800d to get alerts and that's all.
@debarko ty..sorry..tk cr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
auto book script is giving unauthorized access error response. How do i fix it?