-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait4vax4nyc.js
executable file
·160 lines (146 loc) · 4.08 KB
/
wait4vax4nyc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env node
var fetch = require('node-fetch');
if(process.argv.length < 5) {
console.error("Usage:", process.argv[0], "<date of birth>", "<zip code>", "<range in miles>", "[email]");
console.error("e.g.:", process.argv[0], "1975-10-20", "10002", "3") ;
process.exit(1);
}
var dob = process.argv[2];
var zip = process.argv[3];
var range = parseInt(process.argv[4]);
if(process.argv.length >= 6) {
email = process.argv[5];
}
var data = {
message: {
"actions": [
{
"id": "91;a",
"descriptor": "aura://ApexActionController/ACTION$execute",
"callingDescriptor": "UNKNOWN",
"params": {
"namespace": "",
"classname": "VCMS_BookAppointmentCtrl",
"method": "fetchDataWrapper",
"params": {
"isOnPageLoad": false,
"scheduleDate": "2021-03-30",
"zipCode": "10002",
"selectedVeventId": null,
"selectedVeventDate": null,
"selectedSlotTime": null,
"isSecondDose": false,
"appointmentSlotId": null,
"vaccineName": "",
"isReschedule": false,
"isClinicPortal": false,
"isCallCenter": false,
"patientZipCode": "10002",
"patientDob": "1975-10-20",
"patientEligibility": [
"People ages 65 and older"
]
},
"cacheable": false,
"isContinuation": false
}
}
]
},
aura: {
context: {
"mode": "PROD",
"fwuid": "Q8onN6EmJyGRC51_NSPc2A",
"app": "siteforce:communityApp",
"loaded": {
"APPLICATION@markup://siteforce:communityApp": "XrAWq7KlNf8wSyobBsPNEA"
},
"dn":[],
"globals":{},
"uad":false
},
pageURI: "/patient/s/vaccination-schedule",
token: undefined
}
};
function paramsToString(params) {
return Object.keys(params).map(key => {
var value = params[key];
if(typeof value === "object") {
value = JSON.stringify(value);
}
return key+"="+encodeURIComponent(value);
}).join("&");
}
function check4vax() {
console.error(new Date(), "Checking...");
var params = {
message: data.message
};
Object.keys(data.aura).forEach(key => {
var value = data.aura[key];
params["aura."+key] = value;
});
var paramsString = paramsToString(params);
var url = "https://vax4nyc.nyc.gov/patient/s/sfsites/aura?r=9&aura.ApexAction.execute=1";
return fetch(url, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" }, body: paramsString}).then(response => response.json());
}
var params = data.message.actions[0].params.params;
params.zipCode = zip;
params.patientZipCode = zip;
params.patientDob = dob;
var date = new Date();
params.scheduleDate = [ date.getFullYear(), ("0"+(date.getMonth()+1)).slice(-2), ("0"+date.getDate()).slice(-2) ].join("-");
function checkAndRepeat() {
check4vax()
.then(response => {
//console.error("Response", JSON.stringify(response, null, 4));
var results = response.actions[0].returnValue.returnValue.lstMainWrapper;
if(results.length > 0) {
results = results[0].lstDataWrapper;
}
/*
if(results.length > 0) {
console.error("Unfiltered", JSON.stringify(results, null, 4));
}
*/
if(range) {
results = results.filter(result => result.mileRange < range);
// console.error("Filtered", JSON.stringify(results, null, 4));
}
if(results.length > 0) {
console.log(JSON.stringify(results, null, 4));
sendMail(results);
return;
}
setTimeout(checkAndRepeat, 300000);
});
}
checkAndRepeat();
function sendMail(results) {
var nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
port: 25,
host: 'localhost',
tls: {
rejectUnauthorized: false
},
});
var message = {
from: '[email protected]',
to: email,
subject: `${results.length} results in ${range} miles for ${zip}`,
text: `
https://vax4nyc.nyc.gov/patient/s/ to register for vaccine.
`,
html: `
<a href="https://vax4nyc.nyc.gov/patient/s/">https://vax4nyc.nyc.gov/patient/s/</a> to register for vaccine.
`,
};
transporter.sendMail(message, (error, info) => {
if (error) {
return console.log(error);
}
console.error('Message sent: %s', info.messageId);
});
}