Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PREFERRED_VACCINE and NO_OF_DAYS_TO_CHECK feature #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ EMAIL=
APPLICATION_PASSWORD=
AGE=

#Optional Values
NO_OF_DAYS_TO_CHECK=
PREFERRED_VACCINE=

#Example:
#PINCODE=201301
#[email protected]
#APPLICATION_PASSWORD=askdjklj11aklsj
#AGE=53
#NO_OF_DAYS_TO_CHECK=2
#PREFERRED_VACCINE=COVAXIN,COVISHIELD
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# VaccineNotifier
VaccineNotifier checks the cowin portal periodically to find vaccination slots available in your pin code and for your age. If found, it will send you emails every minute until the slots are available.

VaccineNotifier checks the cowin portal periodically to find vaccination slots available in your pin code and for your age. Optionally you can also give NO_OF_DAYS_TO_CHECK (default value is next 10 days) & and you also add your preferred vaccines(by default it considers all vaccines ). If there is match for your requirement, it will send you emails every minute until the slots are available.

<font size="6"> Steps to run the script: </font>
<font size="6"> Steps to run the script: </font>

Step 1) Enable application access on your gmail with steps given here:
https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637554658548216477-2576856839&rd=1
Expand Down
12 changes: 7 additions & 5 deletions vaccineNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ To close the app, run: pm2 stop vaccineNotifier.js && pm2 delete vaccineNotifier
const PINCODE = process.env.PINCODE
const EMAIL = process.env.EMAIL
const AGE = process.env.AGE
const NO_OF_DAYS_TO_CHECK = Number(process.env.NO_OF_DAYS_TO_CHECK) || 10
const PREFERRED_VACCINE_LIST = process.env.PREFERRED_VACCINE.split(',')

async function main(){
try {
cron.schedule('* * * * *', async () => {
cron.schedule('*/5 * * * *', async () => {
await checkAvailability();
});
} catch (e) {
Expand All @@ -31,7 +33,7 @@ async function main(){

async function checkAvailability() {

let datesArray = await fetchNext10Days();
let datesArray = await fetchNextDays();
datesArray.forEach(date => {
getSlotsForDate(date);
})
Expand All @@ -50,7 +52,7 @@ function getSlotsForDate(DATE) {
axios(config)
.then(function (slots) {
let sessions = slots.data.sessions;
let validSlots = sessions.filter(slot => slot.min_age_limit <= AGE && slot.available_capacity > 0)
let validSlots = sessions.filter(slot => slot.min_age_limit <= AGE && slot.available_capacity > 0 && (PREFERRED_VACCINE_LIST.length >0 || PREFERRED_VACCINE_LIST.indexOf(slot.vaccine)) )
console.log({date:DATE, validSlots: validSlots.length})
if(validSlots.length > 0) {
notifyMe(validSlots);
Expand All @@ -72,10 +74,10 @@ notifyMe(validSlots){
})
};

async function fetchNext10Days(){
async function fetchNextDays(){
let dates = [];
let today = moment();
for(let i = 0 ; i < 10 ; i ++ ){
for(let i = 0 ; i < NO_OF_DAYS_TO_CHECK ; i ++ ){
let dateString = today.format('DD-MM-YYYY')
dates.push(dateString);
today.add(1, 'day');
Expand Down