Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
Add support for search by pin code
Browse files Browse the repository at this point in the history
Now you can check and get notified about your pin code only.
  • Loading branch information
pramodpots committed May 10, 2021
1 parent dd84f4b commit a7c77d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function checkParams() {
} else if (!argv.age) {
console.error('Please provide your age by appending --age=<YOUR-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=<DISTRICT-ID> \nRefer documentation for more details');
return;
} else if (argv.interval && argv.interval < 5) {
Expand All @@ -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) {
Expand All @@ -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/calendarByDistrict?pincode=${pin}&date=${date}`
}
axios.get(url, { headers: { 'User-Agent': sampleUserAgent } }).then((result) => {
const { centers } = result.data;
let isSlotAvailable = false;
let dataOfSlot = "";
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Replace the arguments above with the required values like mentioned below

- Replace `<YOUR-AGE>` with your age.

Not required if used --pin
- Replace `<DISTRICT-ID>` with your district's id from this [list](#district_list).

Optional arguments accepted:

- Pass `--interval=<INTERVAL-IN-MINUTES>` to change the frequency of calling Cowin API (default is 15 mins).
- Pass `--appts=<APPOINTMENT-COUNT>` to specify the number of session details you want to receive in the notification (default is 2).
- Pass `--pin=<YOUR-AREA-PIN-CODE>` 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.
Expand Down

0 comments on commit a7c77d2

Please sign in to comment.