-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhudas-manilacovid19vaccine-downloader.js
206 lines (175 loc) · 8.34 KB
/
hudas-manilacovid19vaccine-downloader.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
const axios = require('axios').default;
const download = require('download');
const inquirer = require('inquirer');
const fs = require('fs');
const chalk = require('chalk');
const timer = ms => new Promise(res => setTimeout(res, ms))
async function main() {
console.clear()
if (!fs.existsSync(process.cwd() + `/documents/`)) {
fs.mkdirSync(process.cwd() + `/documents/`);
console.log(chalk.green('Created Documents Folder\n'))
}
let getMethod = await inquirer.prompt({
type: "list",
name: "type",
message: "Get Vaccination Data using",
choices: ["Registered Mobile Number and First Name", "QR Code (For QR Code Scan your qr code first and paste here the result)"]
});
if (getMethod.type === "Registered Mobile Number and First Name") {
let inputPrompts = [{
type: "input",
name: "mobileNumber",
message: "Please enter the registered mobile number",
},
{
type: "input",
name: "firstName",
message: "Please enter the registered first name",
}];
let inputInquirer = await inquirer.prompt(inputPrompts);
loginUsingNumberName(inputInquirer.mobileNumber, inputInquirer.firstName)
} else {
console.log(chalk.red.bold('\nWARNING: ') + chalk.yellow('The website is using rate limitation and might block you for a minute when using this method.\n'));
let inputPrompts = [{
type: "input",
name: "referenceID",
message: "Please enter or paste the scanned value of qr code",
},
{
type: "input",
name: "registrationID",
message: "Please enter a number where you want to start. Leave blank to start from 0.",
}];
let inputInquirer = await inquirer.prompt(inputPrompts);
var registrationID = '0'
var response = false;
if (inputInquirer.registrationID) {
registrationID = inputInquirer.registrationID
}
while (!response) {
console.log(chalk.blue('TRIES ' + registrationID))
await timer(500);
response = await getData(registrationID, inputInquirer.referenceID)
if (response === 403 || response === 429) {
response = false;
console.log(chalk.yellow('RATE LIMITED SLEEPING FOR 2 MINUTES'))
await timer(1000 * 60 * 2);
} else if (response === true) {
console.log(chalk.green('DOWNLOAD DONE'))
process.stdin.resume();
} else {
registrationID++
}
}
}
}
main();
async function loginUsingNumberName(mobileNumber, firstName) {
const login = await axios({
method: 'get',
url: `https://www.manilacovid19vaccine.ph/search-otp-ajax.php?MobileNo=${mobileNumber}&FirstName=${firstName}`,
})
var registrationID = login.data.split('!')[1]
var referenceID = login.data.split('!')[2]
var data = await getData(registrationID, referenceID)
if (data) {
console.log(chalk.bold.green('\nDOWNLOAD DONE'))
process.stdin.resume();
}
}
async function getData(registrationID, referenceID) {
const verify = await axios({
method: 'get',
url: `https://www.manilacovid19vaccine.ph/search-registration-ajax.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`,
withCredentials: true,
})
var getCert
try {
getCert = await axios({
method: 'get',
url: `https://www.manilacovid19vaccine.ph/my-passport-certificate-print.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`,
withCredentials: true,
headers: {
crossDomain: true,
cookie: verify.headers['set-cookie']
},
})
} catch (error) {
return error.response.status
}
if (!getCert.data.includes('<script>')) {
if (!fs.existsSync(process.cwd() + `/documents/${referenceID}/`)) {
fs.mkdirSync(process.cwd() + `/documents/${referenceID}/`);
console.log(chalk.green(`\nCreated '/documents/${referenceID}/' Folder\n`))
}
fs.writeFileSync(`documents/${referenceID}/waiver.pdf`, await download(`https://www.manilacovid19vaccine.ph/waiver.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`));
console.log(chalk.green('DOWNLOADED Waiver OF ' + referenceID))
fs.writeFileSync(`documents/${referenceID}/passport-vaccination-id.pdf`, await download(`https://www.manilacovid19vaccine.ph/my-passport-vaccination-id.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`, '', {
headers: {
cookie: verify.headers['set-cookie']
}
}));
console.log(chalk.green('DOWNLOADED Vaccination ID OF ' + referenceID))
fs.writeFileSync(`documents/${referenceID}/passport-vaccination-id-back.pdf`, await download(`https://www.manilacovid19vaccine.ph/my-passport-vaccination-id-back.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`, '', {
headers: {
cookie: verify.headers['set-cookie']
}
}));
console.log(chalk.green('DOWNLOADED Vaccination ID Back OF ' + referenceID))
fs.writeFileSync(`documents/${referenceID}/vaccination-certificate.pdf`, await download(`https://www.manilacovid19vaccine.ph/my-passport-certificate-print.php?RegistrationID=${registrationID}&ReferenceID=${referenceID}`, '', {
headers: {
cookie: verify.headers['set-cookie']
}
}));
console.log(chalk.green('DOWNLOADED Vaccination Certificate OF ' + referenceID + '\n'))
const getFamily = await axios({
method: 'get',
url: `https://manilacovid19vaccine.ph/my-passport-family.php`,
withCredentials: true,
headers: {
crossDomain: true,
cookie: verify.headers['set-cookie']
},
})
var familyMembers = [];
getFamily.data.match(/href="my-passport-family-members([^"]*)"/g).forEach(element => {
familyMembers.push('https://manilacovid19vaccine.ph/' + element.replace('href=', '').replace('"', '').replace('"', ''))
});
for (const element of familyMembers) {
var famReferenceID = element.split('?')[1].split('&')[1].replace('ReferenceID=', '');
if (famReferenceID != referenceID) {
if (!fs.existsSync(process.cwd() + `/documents/${referenceID}/family/`)) {
fs.mkdirSync(process.cwd() + `/documents/${referenceID}/family/`);
console.log(chalk.green(`Created '/documents/${referenceID}/family/' Folder`))
}
if (!fs.existsSync(process.cwd() + `/documents/${referenceID}/family/${famReferenceID}/`)) {
fs.mkdirSync(process.cwd() + `/documents/${referenceID}/family/${famReferenceID}/`);
console.log(chalk.green(`Created '/documents/${referenceID}/family/${famReferenceID}/' Folder\n`))
}
var fileName;
if (element.includes('my-passport-family-members-waiver-registration.php')) {
fileName = 'waiver'
} else if (element.includes('my-passport-family-members-vaccination-id.php')) {
fileName = 'vaccination-id'
} else if (element.includes('my-passport-family-members-vaccination-id-back.php')) {
fileName = 'vaccination-id-back'
} else if (element.includes('my-passport-family-members-vaccination-certificate.php')) {
fileName = 'vaccination-certificate'
}
fs.writeFileSync(`documents/${referenceID}/family/${famReferenceID}/${fileName}.pdf`, await download(element, '', {
headers: {
cookie: verify.headers['set-cookie']
}
}));
if (fileName === 'vaccination-certificate') {
console.log(chalk.green(`DOWNLOADED FAMILY ${fileName} OF ${famReferenceID}\n`))
} else {
console.log(chalk.green(`DOWNLOADED FAMILY ${fileName} OF ${famReferenceID}`))
}
}
}
return true
}
return false
}