forked from cepem/rovaccine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (54 loc) · 2.12 KB
/
app.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
const cron = require("node-cron");
const fetch = require("node-fetch");
const notifier = require("node-notifier");
const { PROFILE_DATA, VACCINE_TYPES } = require("./config");
const getVaccineSlotsData = () => {
return new Promise((resolve, reject) => {
fetch(
"https://programare.vaccinare-covid.gov.ro/scheduling/api/centres?page=0&size=10&sort=,",
{
headers: {
accept: "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/json",
"sec-ch-ua":
'"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
cookie: PROFILE_DATA.cookie,
},
referrer: "https://programare.vaccinare-covid.gov.ro/",
referrerPolicy: "strict-origin-when-cross-origin",
body: `{"countyID":${PROFILE_DATA.countyID},"localityID":${PROFILE_DATA.localityID},"name":null,"identificationCode":${PROFILE_DATA.identificationCode},"masterPersonnelCategoryID":${PROFILE_DATA.masterPersonnelCategoryID},"personnelCategoryID":${PROFILE_DATA.personnelCategoryID},"recipientID":${PROFILE_DATA.recipientID}}`,
method: "POST",
mode: "cors",
}
)
.then((r) => resolve(r))
.catch((err) => reject(err));
});
};
const parseVaccineResponse = (vaccineResponse) => {
const availableLocations = vaccineResponse.filter(
(item, index) =>
item.availableSlots > 0 && VACCINE_TYPES.includes(item.boosterID)
);
if (availableLocations.length > 0) {
availableLocations.forEach((item, index) => {
notifier.notify({
title: "Sloturi de vaccine disponibile!",
message: `${item.availableSlots} Sloturi la: ${item.name} | ${item.address} `,
});
});
}
if (availableLocations.length === 0) {
console.log("N-au fost găsite slot-uri");
}
};
cron.schedule("*/30 * * * * *", () => {
getVaccineSlotsData()
.then((r) => r.text())
.then((r2) => parseVaccineResponse(JSON.parse(r2).content));
});