Last active
June 10, 2021 16:16
-
-
Save dpacmittal/35059f6ad578ebd9024a79027f1d6e6d to your computer and use it in GitHub Desktop.
Ping co-win vaccine api to check for availability and show notification using zenity
This file contains hidden or 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
const fetch = require('node-fetch'); | |
const { exec } = require("child_process"); | |
async function main(){ | |
const districts = [ | |
{ district_id: 294, district_name: 'BBMP' }, | |
{ district_id: 265, district_name: 'Bangalore Urban' }, | |
{ district_id: 276, district_name: 'Bangalore Rural' }, | |
// { district_id: 363, district_name: "Pune" }, | |
// { district_id: 270, district_name: 'Bagalkot' }, | |
// { district_id: 264, district_name: 'Belgaum' }, | |
// { district_id: 274, district_name: 'Bellary' }, | |
// { district_id: 272, district_name: 'Bidar' }, | |
// { district_id: 271, district_name: 'Chamarajanagar' }, | |
// { district_id: 273, district_name: 'Chikamagalur' }, | |
// { district_id: 291, district_name: 'Chikkaballapur' }, | |
// { district_id: 268, district_name: 'Chitradurga' }, | |
// { district_id: 269, district_name: 'Dakshina Kannada' }, | |
// { district_id: 275, district_name: 'Davanagere' }, | |
// { district_id: 278, district_name: 'Dharwad' }, | |
// { district_id: 280, district_name: 'Gadag' }, | |
// { district_id: 267, district_name: 'Gulbarga' }, | |
// { district_id: 289, district_name: 'Hassan' }, | |
// { district_id: 279, district_name: 'Haveri' }, | |
// { district_id: 283, district_name: 'Kodagu' }, | |
// { district_id: 277, district_name: 'Kolar' }, | |
// { district_id: 282, district_name: 'Koppal' }, | |
// { district_id: 290, district_name: 'Mandya' }, | |
// { district_id: 266, district_name: 'Mysore' }, | |
// { district_id: 284, district_name: 'Raichur' }, | |
// { district_id: 292, district_name: 'Ramanagara' }, | |
// { district_id: 287, district_name: 'Shimoga' }, | |
// { district_id: 288, district_name: 'Tumkur' }, | |
// { district_id: 286, district_name: 'Udupi' }, | |
// { district_id: 281, district_name: 'Uttar Kannada' }, | |
// { district_id: 293, district_name: 'Vijayapura' }, | |
// { district_id: 285, district_name: 'Yadgir' } | |
]; | |
for(let dis=0; dis<districts.length; dis++) { | |
const distid = districts[dis].district_id; | |
const date = new Date().toISOString().split('T')[0].split('-').reverse().join('-'); | |
const req = await fetch(`https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByDistrict?district_id=${distid}&date=${date}`, { | |
"credentials": "include", | |
"headers": { | |
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", | |
"Accept": "application/json, text/plain, */*", | |
"Accept-Language": "en-US,en;q=0.5", | |
"Pragma": "no-cache", | |
"Cache-Control": "no-cache" | |
}, | |
"referrer": "https://selfregistration.cowin.gov.in/", | |
"method": "GET", | |
"mode": "cors" | |
}); | |
const resp = await req.json(); | |
if(resp?.centers?.length < 1) { | |
console.log("Request failed"); | |
} | |
const available_centers = resp?.centers?.filter(center=> { | |
//console.log(center); | |
const sessions = center?.sessions?.filter(session => { | |
return session.min_age_limit == 18 && session.available_capacity_dose1 > 5; | |
}); | |
return sessions?.length > 0; | |
}); | |
if(available_centers?.length > 0) { | |
console.log(new Date().toISOString(), "VACCINE AVAILABLE!! ๐"); | |
let pincodes = []; | |
available_centers.map(center=> { | |
pincodes.push(center.name + ', ' + center.pincode + ', ' + center.district_name); | |
}) | |
exec(`zenity --info --width 1200 height 500 --text "VACCINE AVAILABLE!!!\n ${pincodes.join("\n")}"`); | |
} | |
else { | |
console.log(new Date().toISOString(), "No vaccine ๐"); | |
} | |
} | |
} | |
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | |
async function start() { | |
while(true){ | |
main(); | |
await delay(15000); | |
} | |
} | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment