diff --git a/README.md b/README.md index ba7ca03..92d2d40 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,10 @@ 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 **7** but, you can change it to 10 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 hour at minute 5 and second 0**. 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. +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 **7** but, you can change it to 10 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 hour at minute 0 and minute 30; second 0**. 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 = '0 5 * * * *'; +const SCHEDULE = '0 0,30 * * * *'; const DATE_RANGE = 7; ``` diff --git a/package.json b/package.json index c5d3054..3736e35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "covid-19-vaccine-alerts-cowin", - "version": "1.0.3", + "version": "1.0.4", "description": "This is an alerting application that sends email notifications to beneficiaries in India using COWIN platform for vaccine availability", "main": "src/app.js", "scripts": { diff --git a/src/app.js b/src/app.js index 308f803..1751b0a 100644 --- a/src/app.js +++ b/src/app.js @@ -152,7 +152,7 @@ async function sendEmailAlert(slotsArray) { } firstRun = false; runCounter = runCounter + 1; - await dailyDigest.updateRunCounter(runCounter, vaccinationSlots); + await dailyDigest.updateRunStatistics(runCounter, outputArray); await resetDailyCounter(); }; diff --git a/src/configs/schedulerConfig.js b/src/configs/schedulerConfig.js index 761a723..eef50c0 100644 --- a/src/configs/schedulerConfig.js +++ b/src/configs/schedulerConfig.js @@ -1,4 +1,4 @@ -const SCHEDULE = '0 5 * * * *'; +const SCHEDULE = '0 0,30 * * * *'; const DATE_RANGE = 7; const DATE_FORMAT = 'DD-MM-YYYY'; const DELAY = 60000; diff --git a/src/utilities/dailyDigest.js b/src/utilities/dailyDigest.js index f512233..844395f 100644 --- a/src/utilities/dailyDigest.js +++ b/src/utilities/dailyDigest.js @@ -5,13 +5,13 @@ const htmlBuilder = require('../utilities/htmlBuilder'); const logger = require('../utilities/logger'); let runs = 0; -let slots = []; +let uniqueSlots = []; async function prepareReport () { let regionType = Boolean(appConfig.FINDBYPINCODE) ? 'pincode' : 'district'; let region = regionType == 'pincode' ? appConfig.PINCODE : appConfig.DISTRICT; alerts.sendEmailAlert(mailConfig.DAILY_DIGEST_SUBJECT, - await htmlBuilder.prepareDailyDigestEmail(runs, slots.length, regionType, region), (error, result) => { + await htmlBuilder.prepareDailyDigestEmail(runs, uniqueSlots.length, regionType, region), (error, result) => { if(error) { console.log(logger.getLog(error)); } else { @@ -20,9 +20,19 @@ async function prepareReport () { }); } -async function updateRunCounter (runCounter, vaccinationSlots) { +async function updateRunStatistics (runCounter, outputArray) { + let slots = uniqueSlots; + let centersArray = await getCenters(outputArray); + uniqueSlots = [...new Set([...slots,...centersArray])]; runs = runCounter; - slots = vaccinationSlots; } -module.exports = { prepareReport, updateRunCounter }; +async function getCenters (outputArray) { + let centersArray = []; + for(let counter = 0; counter < outputArray.length; counter++) { + centersArray.push(outputArray[counter].center_id.toString()); + } + return centersArray; +} + +module.exports = { prepareReport, updateRunStatistics }; diff --git a/src/utilities/htmlBuilder.js b/src/utilities/htmlBuilder.js index 5f94952..da396ac 100644 --- a/src/utilities/htmlBuilder.js +++ b/src/utilities/htmlBuilder.js @@ -84,7 +84,7 @@ async function prepareDailyDigestEmail(runs, centers, regionType, region) {
Welcome to the ${mailConfig.SENDER} daily digest. A summary of results obtained today are gathered and presented below:<\p>
The application periodically checked for new vaccination slots ${runs} times today.<\p> -
Total number of vaccination centers with available slots found for ${regionType} \(${region}\) were: ${centers}<\p> +
Total number of vaccination centers with available slots found today for ${regionType} \(${region}\) were: ${centers}<\p>
The application will continue to look for new slots in your requested region and send alerts tomorrow.<\p>