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

Commit

Permalink
Merge pull request #4 from abhinavdc/notification-from-terminal
Browse files Browse the repository at this point in the history
Allow script to work without IFTTT
  • Loading branch information
abhinavdc authored May 6, 2021
2 parents 6c3fffd + 4e304dc commit 95e17c7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
40 changes: 29 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const axios = require('axios')
const argv = require('minimist')(process.argv.slice(2));
const { format } = require('date-fns');
const startOfTomorrow = require('date-fns/startOfTomorrow')
const sound = require("sound-play");
const path = require("path");
const notificationSound = path.join(__dirname, "sounds/beep.mp3");

const defaultInterval = 15; // interval between pings in minutes
const appointmentsListLimit = 2 // Increase/Decrease it based on the amount of information you want in the notification.
Expand All @@ -15,11 +18,14 @@ function checkParams() {
if (argv.help) {
console.error('Refer documentation for more details');
} else if (argv._ && argv._.length && argv._.includes('run')) {
if (!argv.key || typeof argv.key !== 'string') {
console.error('Please provide a valid IFTTT Webook API Key by appending --key=<IFTTT-KEY> \nRefer documentation for more details');
if (argv.key && typeof argv.key !== 'string') {
console.error('Please provide a valid IFTTT Webook API Key by appending --key=<IFTTT-KEY> to recieve mobile notification \nRefer documentation for more details');
return;
} else if (!argv.hook || typeof argv.hook !== 'string') {
console.error('Please provide a valid IFTTT Webook Name Key by appending --hook=<IFTTT-WEBHOOK-NAME> \nRefer documentation for more details');
} else if (argv.hook && typeof argv.hook !== 'string') {
console.error('Please provide a valid IFTTT Webook Name Key by appending --hook=<IFTTT-WEBHOOK-NAME> to recieve mobile notification \nRefer documentation for more details');
return;
} else if (argv.hook && !argv.key || !argv.hook && argv.key) {
console.error('Please provide both IFTTT Webook Name Key and IFTTT Webhook Key to recieve mobile notification \nRefer documentation for more details');
return;
} else if (!argv.age) {
console.error('Please provide your age by appending --age=<YOUR-AGE> \nRefer documentation for more details');
Expand All @@ -43,13 +49,17 @@ function checkParams() {
}

console.log('\nCowin Pinger started succesfully\n');
console.log(`IFTTT API Key= ${params.key}`);
console.log(`IFTTT Hook Name= ${params.hook}`);
console.log(`Age= ${params.age}`);
console.log(`District ID= ${params.districtId}`);
console.log(`Time interval= ${params.interval} minutes (default is 15)`);
console.log(`Appointment Count= ${params.appointmentsListLimit} (default is 2)\n\n`);

console.log(`Appointment Count= ${params.appointmentsListLimit} (default is 2)`);
if (params.hook && params.key) {
console.log(`IFTTT API Key= ${params.key || "not configured"}`);
console.log(`IFTTT Hook Name= ${params.hook || "not configured"}`);
} else {
console.log('\nMake sure to turn up the volume to hear the notifcation sound')
}
console.log('\n\n')
scheduleCowinPinger(params);
}
} else {
Expand Down Expand Up @@ -89,10 +99,18 @@ function pingCowin({ key, hook, age, districtId, appointmentsListLimit, date })
dataOfSlot = `${dataOfSlot}\n${appointmentsAvailableCount - appointmentsListLimit} more slots available...`
}
if (isSlotAvailable) {
axios.post(`https://maker.ifttt.com/trigger/${hook}/with/key/${key}`, { value1: dataOfSlot }).then(() => {
console.log('Sent Notification to Phone \nStopping Pinger...')
if (hook && key) {
axios.post(`https://maker.ifttt.com/trigger/${hook}/with/key/${key}`, { value1: dataOfSlot }).then(() => {
console.log('Sent Notification to Phone \nStopping Pinger...')
sound.play(notificationSound);
clearInterval(timer);
});
} else {
console.log(dataOfSlot);
console.log('Slots found\nStopping Pinger...')
sound.play(notificationSound);
clearInterval(timer);
});
}
}
}).catch((err) => {
console.log("Error: " + err.message);
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cowin-pinger",
"version": "0.0.6",
"version": "1.0.0",
"description": "Get notified on your phone when there is a vaccine slot available at your location, by running a script on your computer. Uses Cowin portal's public API.",
"main": "app.js",
"scripts": {
Expand All @@ -11,7 +11,8 @@
"dependencies": {
"axios": "^0.21.1",
"date-fns": "^2.21.1",
"minimist": "^1.2.5"
"minimist": "^1.2.5",
"sound-play": "^1.1.0"
},
"repository": {
"type": "git",
Expand All @@ -20,4 +21,4 @@
"bin": {
"cowin-pinger": "./app.js"
}
}
}
28 changes: 17 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# COWIN VACCINE AVAILABILITY NOTIFIER
Get notified on your phone when there is a vaccine slot available at your location, by running a script on your computer. Uses Co-Win public APIs.
Get notified on your phone when there is a vaccine slot available at your location, by running a script on your computer. Uses Co-Win public APIs.

Update: Now works without IFTTT by playing a notification sound when a slot is found.

![Instructions-GIF](https://github.com/abhinavdc/cowin-pinger/blob/main/img/instructions.gif)

## GETTING STARTED
### Run cowin-pinger

Install [node](https://nodejs.org/en/download/), if not already installed. Then run the following command:

npx cowin-pinger run --key=<IFTTT-KEY> --hook=<IFTTT-WEBHOOK-NAME> --age=<YOUR-AGE> --district=<DISTRICT-ID>
npx cowin-pinger run --age=<YOUR-AGE> --district=<DISTRICT-ID>

Replace the arguments above with the required values like mentioned below

- Replace `<IFTTT-KEY>` with your WebHook Key from IFTTT.

- Replace `<IFTTT-WEBHOOK-NAME>` with the name you used for the WebHook in IFTTT.

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

- Replace `<DISTRICT-ID>` with your district's id from this [list](#district_list).
Expand All @@ -25,13 +22,22 @@ 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).

### Setting Up IFTTT for WebHook Name and Key
## IFTTT Integration (Optional)
By integrating with [IFTTT](https://ifttt.com/) you can recieve the notification on your phone.
- ### Setting Up IFTTT

- Follow the steps mentioned in the [article](https://betterprogramming.pub/how-to-send-push-notifications-to-your-phone-from-any-script-6b70e34748f6) to setup IFTTT.

- Install IFTTT App on phone to recieve notifications

- Follow the steps mentioned in the [article](https://betterprogramming.pub/how-to-send-push-notifications-to-your-phone-from-any-script-6b70e34748f6) to setup IFTTT.
- Test if you receive notification like mentioned in the article above.
- ### Run Cowin-Pinger with IFTTT Configuration

- Install IFTTT App on phone to recieve notifications
npx cowin-pinger run --key=<IFTTT-KEY> --hook=<IFTTT-WEBHOOK-NAME> --age=<YOUR-AGE> --district=<DISTRICT-ID>

- Replace `<IFTTT-KEY>` with your WebHook Key from IFTTT.

- Test if you receive notification like mentioned in the article above.
- Replace `<IFTTT-WEBHOOK-NAME>` with the name you used for the WebHook in IFTTT.

## <a name="district_list">District IDs</a>

Expand Down
Binary file added sounds/beep.mp3
Binary file not shown.

0 comments on commit 95e17c7

Please sign in to comment.