diff --git a/app.js b/app.js index e8b5d78..ca2a20f 100755 --- a/app.js +++ b/app.js @@ -30,7 +30,7 @@ function checkParams() { } else if (!argv.age) { console.error('Please provide your age by appending --age= \nRefer documentation for more details'); return; - } else if (!argv.district) { + } else if (!argv.district && !argv.pin) { console.error('Please provide required district id by appending --district= \nRefer documentation for more details'); return; } else if (argv.interval && argv.interval < 5) { @@ -45,12 +45,14 @@ function checkParams() { districtId: argv.district, interval: argv.interval || defaultInterval, appointmentsListLimit: argv.appts || appointmentsListLimit, - date: format(startOfTomorrow(), 'dd-MM-yyyy') + date: format(startOfTomorrow(), 'dd-MM-yyyy'), + pin: argv.pin } console.log('\nCowin Pinger started succesfully\n'); console.log(`Age= ${params.age}`); console.log(`District ID= ${params.districtId}`); + console.log(`Pin Code= ${params.pin}`); console.log(`Time interval= ${params.interval} minutes (default is 15)`); console.log(`Appointment Count= ${params.appointmentsListLimit} (default is 2)`); if (params.hook && params.key) { @@ -77,8 +79,12 @@ function scheduleCowinPinger(params) { }, params.interval * 60000); } -function pingCowin({ key, hook, age, districtId, appointmentsListLimit, date }) { - axios.get(`https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=${districtId}&date=${date}`, { headers: { 'User-Agent': sampleUserAgent } }).then((result) => { +function pingCowin({ key, hook, age, districtId, appointmentsListLimit, date, pin }) { + let url = `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=${districtId}&date=${date}` + if (pin) { + url = `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin?pincode=${pin}&date=${date}` + } + axios.get(url, { headers: { 'User-Agent': sampleUserAgent } }).then((result) => { const { centers } = result.data; let isSlotAvailable = false; let dataOfSlot = ""; diff --git a/readme.md b/readme.md index 123773d..3356984 100644 --- a/readme.md +++ b/readme.md @@ -15,12 +15,14 @@ Replace the arguments above with the required values like mentioned below - Replace `` with your age. +Not required if used --pin - Replace `` with your district's id from this [list](#district_list). Optional arguments accepted: - Pass `--interval=` to change the frequency of calling Cowin API (default is 15 mins). - Pass `--appts=` to specify the number of session details you want to receive in the notification (default is 2). + - Pass `--pin=` to get only notification about your pin code. ## IFTTT Integration (Optional) By integrating with [IFTTT](https://ifttt.com/) you can recieve the notification on your phone.