diff --git a/README.md b/README.md index 6af07e7..379e1c9 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,33 @@ # COVID-19 Vaccine Alerts - COWIN -This repository is an alerting application that sends email notifications to beneficiaries in India using COWIN platform for vaccine availability. The application interacts with the COWIN API at regular intervals to find vaccination slots available at your pincode location(s) or entire district along with a minimum age limit. SO if you are currently waiting to find slots in your region and do not see any slots for your age range then, you can utilise this application to receive alerts on your email address when there are slots available for you. This way you will be able to book your appointments on time. Remember, vaccination is highly beneficial for you in this horrific time of crisis. Get your jab and protect yourself from serious illness. +This repository is an alerting application that sends email notifications to beneficiaries in India using [COWIN platform](https://www.cowin.gov.in/home) for vaccine availability. The application interacts with the [COWIN API](https://apisetu.gov.in/public/marketplace/api/cowin) at regular intervals to find vaccination slots available at your pin code location(s) or entire district along with a minimum age limit. So, if you are currently waiting to find slots in your region and do not see any slots for your age range then, you can utilise this application to receive alerts on your email address when there are slots available for you. This way you will be able to book your appointments on time. Remember, vaccination is highly beneficial for you in this horrific time of crisis. Get your jab and protect yourself from serious illness. Here is a sample email alert from this application containing all the required information regarding available slots: ![sample alert](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/sample-alert.png?raw=true) -## How to run this application? +## Application overview and pre-requisites -Firslt, clone/ download this GitHub project on your system/ server. The application is built using Node.js so you would need to setup node and npm on your local machine/ server where you want to run this. Use the [Node.js](https://nodejs.org/en/download "Node.js Homepage") link to install Node.js on your respective platform (Windows/ macOS/ Linux). You can also use Homebrew or RPM libraries to set it up. In the former case, proceed with installation. +Firstly, clone/ download this GitHub project on your system/ server. The application is built using Node.js so you would need to setup node and npm on your local machine/ server where you want to run this. Use the [Node.js](https://nodejs.org/en/download "Node.js Homepage") link to install Node.js on your respective platform (Windows/ macOS/ Linux). You can also use Homebrew or RPM libraries to set it up. In the former case, proceed with installation. -Open Terminal (macOS/ Linux) or GitBash (Windows) and Enter `node - v` to verify that Node.js is installed correctly and to see the version of Node.js that was installed. +Open Terminal (macOS/ Linux) or GitBash (Windows) and Enter `node - v` to verify that Node.js is installed correctly and to see the version of Node.js that was installed. See below: ``` $ node -v v16.0.0 ``` -If a version was output, then you're all set. The Node.js installer includes the NPM package manager as well so you can also run npm commands as below. Execute `npm -v` to verify. +If a version was output, then you're all set. The Node.js installer includes the NPM package manager as well so you can also run npm commands as below. Execute `npm -v` to verify as below: ``` $ npm -v 7.11.2 ``` -All good? Let's proceed to setup your google account configurations to send email notifications. Visit the [Google Support](https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637554658548216477-2576856839&rd=1 "Google Account Support") link to enable application access on your Gmail account. Follow the **Create & use App Passwords** heading to generate a 16-character code. Copy the code and save it somewhere. Create a file called `.env` in the home path of the project and copy the below content into that file and save. +All good? Let's proceed to customise the application for your personal use. + +## Customise the application for yourself + +Setup your google account configurations to send email notifications. Visit the [Google Support](https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637554658548216477-2576856839&rd=1 "Google Account Support") link to enable application access on your Gmail account. Follow the **Create & use App Passwords** heading to generate a 16-character code. Copy the code and save it somewhere. Create a file called `.env` in the home path of the project and copy the below content into that file and save. ``` APPLICATION_PASSWORD=the-16-character-code-you-generated-in-the-previous-step @@ -39,7 +43,43 @@ package.json sample-alert.png src ``` -Let's proceed to run this application. If you want to keep running the application in the background, on your terminal run: + +All config values of the project are present in [`src/configs/`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs) folder. Customise **PINCODE, STATE, DISTRICT, EMAIL, and AGE** values in [`src/configs/appConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/appConfig.js) file. Set **FINDBYPINCODE = true** if you want to fetch vaccination slots by area pincode(s). You can also set multiple pincodes separated by comma like below: +``` +const FINDBYPINCODE = true; +// location configs +const PINCODE = '800001,800002,800003'; +const STATE = 'BIHAR'; +const DISTRICT = 'PATNA'; +// beneficiary configs +const EMAIL = 'asinha093@gmail.com'; +const AGE = 28; + +``` +When you set **FINDBYPINCODE = false**, the application will fetch vaccination slots by district value mentioned in this config file. + +Customise **RECIPIENT** value in [`src/configs/mailConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/mailConfig.js) file. You can also set **RECIPIENT** value to multiple recipients separated by comma as seen below: +``` +const SERVICE_PROVIDER = 'Gmail'; +const RECIPIENT = 'mail1@gmail.com,mail2@gmail.com,mail3@gmail.com'; +``` + +Finally, you can also alter the date range with which the application will fetch vaccination slots by customising **DATE_RANGE** value in [`src/configs/schedulerConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/schedulerConfig.js) file. By default it is set to **10** but, you can change it to 7 or 15 for example, based on your need. The config file also allows changes in the periodic schedule with which the application runs. By default, **SCHEDULE** value depicts a cron schedule every **3 hours**. To alter this schedule, you need to be familiar with the [cron scheduler](https://linuxhint.com/cron_jobs_complete_beginners_tutorial/#:~:text=The%20scheduled%20commands%20and%20scripts,Task%20Scheduler%20in%20Windows%20OS). I use [Crontab Guru](https://crontab.guru) website to test my cron schedules. + +``` +const SCHEDULE = '* */3 * * *'; +const DATE_RANGE = 10; +``` + +## How to run this application? + +If you want to test the application and run it in foreground run: + +`$ npm install && node src/app.js` + +`Ctrl^C` to exit the process. + +If you want to keep running the application in the background, on your terminal run: `$ npm install && pm2 start src/app.js` @@ -47,6 +87,6 @@ To shutdown the application run: `$ pm2 stop src/app.js && pm2 delete src/app.js` -If you want to run test the application and run it in foreground run: +## Development -`$ npm install && node src/app.js` +This repository is open to contributions and discussion. For any other questions, you can reach out via email at `asinha093@gmail.com`. diff --git a/src/api/routes.js b/src/api/routes.js index bc39ecc..3eab940 100644 --- a/src/api/routes.js +++ b/src/api/routes.js @@ -1,5 +1,5 @@ const axios = require('axios'); -const apiConfig = require('../config/apiConfig'); +const apiConfig = require('../configs/apiConfig'); async function getStates() { let config = { diff --git a/src/app.js b/src/app.js index 59172d4..2b05076 100644 --- a/src/app.js +++ b/src/app.js @@ -2,8 +2,8 @@ require('dotenv').config() const moment = require('moment'); const cron = require('node-cron'); const axios = require('axios'); -const appConfig = require('./config/appConfig'); -const schedulerConfig = require('./config/schedulerConfig'); +const appConfig = require('./configs/appConfig'); +const schedulerConfig = require('./configs/schedulerConfig'); const alerts = require('./services/alerts'); const routes = require('./api/routes'); const locations = require('./utilities/locations'); diff --git a/src/config/schedulerConfig.js b/src/config/schedulerConfig.js deleted file mode 100644 index abacccc..0000000 --- a/src/config/schedulerConfig.js +++ /dev/null @@ -1,5 +0,0 @@ -const SCHEDULE = '* * * * *'; -const DATE_FORMAT = 'DD-MM-YYYY'; -const DATE_RANGE = 10; - -module.exports = { SCHEDULE, DATE_FORMAT, DATE_RANGE }; diff --git a/src/config/apiConfig.js b/src/configs/apiConfig.js similarity index 100% rename from src/config/apiConfig.js rename to src/configs/apiConfig.js diff --git a/src/config/appConfig.js b/src/configs/appConfig.js similarity index 94% rename from src/config/appConfig.js rename to src/configs/appConfig.js index eee1fed..c897808 100644 --- a/src/config/appConfig.js +++ b/src/configs/appConfig.js @@ -5,6 +5,6 @@ const STATE = 'BIHAR'; const DISTRICT = 'PATNA'; // beneficiary configs const EMAIL = 'asinha093@gmail.com'; -const AGE = 45; +const AGE = 28; module.exports = { FINDBYPINCODE, PINCODE, STATE, DISTRICT, EMAIL, AGE }; diff --git a/src/config/mailConfig.js b/src/configs/mailConfig.js similarity index 100% rename from src/config/mailConfig.js rename to src/configs/mailConfig.js diff --git a/src/configs/schedulerConfig.js b/src/configs/schedulerConfig.js new file mode 100644 index 0000000..a4c1773 --- /dev/null +++ b/src/configs/schedulerConfig.js @@ -0,0 +1,5 @@ +const SCHEDULE = '* */3 * * *'; +const DATE_RANGE = 10; +const DATE_FORMAT = 'DD-MM-YYYY'; + +module.exports = { SCHEDULE, DATE_RANGE, DATE_FORMAT }; diff --git a/src/services/alerts.js b/src/services/alerts.js index a51d285..1b4031f 100644 --- a/src/services/alerts.js +++ b/src/services/alerts.js @@ -1,6 +1,6 @@ let mailer = require('nodemailer'); -const appConfig = require('../config/appConfig'); -const mailConfig = require('../config/mailConfig'); +const appConfig = require('../configs/appConfig'); +const mailConfig = require('../configs/mailConfig'); let mailerTransport = mailer.createTransport({ service: mailConfig.SERVICE_PROVIDER, diff --git a/src/utilities/appointments.js b/src/utilities/appointments.js index 19387d1..f17627c 100644 --- a/src/utilities/appointments.js +++ b/src/utilities/appointments.js @@ -1,4 +1,4 @@ -const appConfig = require('../config/appConfig'); +const appConfig = require('../configs/appConfig'); function getFilteredSlots (date, sessions) { let validSlots = sessions.filter(slot => slot.min_age_limit <= appConfig.AGE && slot.available_capacity > 0) diff --git a/src/utilities/htmlBuilder.js b/src/utilities/htmlBuilder.js index 54472cc..155428e 100644 --- a/src/utilities/htmlBuilder.js +++ b/src/utilities/htmlBuilder.js @@ -1,4 +1,4 @@ -const mailConfig = require('../config/mailConfig'); +const mailConfig = require('../configs/mailConfig'); async function prepareHtmlBody(outputArray) { let html = `