-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
128 lines (100 loc) · 6.37 KB
/
index.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
const request = require("request");
const moment = require("moment");
async function getVaccinationCenters(url) {
var options = {
url: url,
encoding: null,
headers: { 'Content-Type': 'application/json' }
};
return new Promise( (resolve, reject) => {
request.get(options, function(err, resp, body) {
if (err) {
console.log(err);
reject(err);
} else {
resolve(body);
}
})
});
}
async function getDoctorInfo(doctorId) {
/*
Ref_visit_motive_ids from: https://api.doctolib.fr/covid_vaccines/
Response: [{"id":37,"name":"astrazeneca","first_shot_ref_visit_motive_id":7107,"second_shot_ref_visit_motive_id":7108},{"id":2,"name":"moderna","first_shot_ref_visit_motive_id":7005,"second_shot_ref_visit_motive_id":7004},{"id":1,"name":"pfizer","first_shot_ref_visit_motive_id":6970,"second_shot_ref_visit_motive_id":6971}]
*/
var options = {
url: `https://www.doctolib.fr/search_results/${doctorId}.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&speciality_id=5494&search_result_format=json&limit=3`,
encoding: null,
headers: { 'Content-Type': 'application/json' }
};
return new Promise( (resolve, reject) => {
request.get(options, function(err, resp, body) {
if (err) {
console.log(err);
reject(err);
} else {
resolve(body);
}
})
});
}
function Sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Main function
(async () => {
/* hard coded searches - replace with your own preference (cityname.json)*/
const vaccinationPlaces = [
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=2',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=3',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=4',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=5',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=6',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=7',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=8',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=9',
'https://www.doctolib.fr/vaccination-covid-19/94130-nogent-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005&page=10',
'https://www.doctolib.fr/vaccination-covid-19/le-perreux-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
'https://www.doctolib.fr/vaccination-covid-19/neuilly-sur-marne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
'https://www.doctolib.fr/vaccination-covid-19/saint-mande.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
'https://www.doctolib.fr/vaccination-covid-19/saint-maur-des-fosses.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
'https://www.doctolib.fr/vaccination-covid-19/rosny-sous-bois.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005',
/*'https://www.doctolib.fr/vaccination-covid-19/meaux.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005%27',
'https://www.doctolib.fr/vaccination-covid-19/melun.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005%27',
'https://www.doctolib.fr/vaccination-covid-19/compiegne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005%27',
'https://www.doctolib.fr/vaccination-covid-19/beauvais.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005%27',
'https://www.doctolib.fr/vaccination-covid-19/beauvais.json?ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&page=2',
'https://www.doctolib.fr/vaccination-covid-19/sezanne.json?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005'*/
]
for (const page of vaccinationPlaces) {
const res = await getVaccinationCenters(page);
const json = JSON.parse(res);
//console.log (json.data.doctors);
for (const doctor of json.data.doctors){
//await Sleep(1000); // throttle - 1 sec between api calls
// look for availabilities for each doctor / center
const avail = await getDoctorInfo(doctor.id);
const availDetails = JSON.parse(avail);
//console.log(availDetails)
if (availDetails.total > 0) {
// get the available slots and make them readable by humans
for (const availability of availDetails.availabilities) {
if (availability.slots.length > 0 ) {
let slots = '';
for (const slot of availability.slots)
{
slots += '[' + moment(slot.start_date).format("hh:mm") + '-' + moment(slot.end_date).format("hh:mm") + ']';
}
console.log ('Found ' + availability.slots.length + ' slots {' + slots + '} on ' + availability.date + ' at ' + doctor.name_with_title + ', ' + doctor.address + ', ' + doctor.city + ' ' + doctor.zipcode);
console.log('\r\n\r\n');
}
}
}
/*
if (availDetails.next_slot) {
console.log ('Found next availability on ' + availDetails.next_slot + ' at ' + doctor.name_with_title + ', ' + doctor.address + ', ' + doctor.city + ' ' + doctor.zipcode);
}*/
}
}
})();