-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpronoteServFinder.js
More file actions
37 lines (33 loc) · 840 Bytes
/
pronoteServFinder.js
File metadata and controls
37 lines (33 loc) · 840 Bytes
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
const https = require('https');
const qs = require('query-string');
module.exports = function getServs(lat, long, cb) {
const rq = https.request({
method: 'POST',
hostname: 'www.index-education.com',
path: '/swie/geoloc.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}, (res) => {
let data = '';
res.on('data', (d) => { data += d.toString(); });
res.on('end', () => {
try {
data = JSON.parse(data);
} catch (_) {
console.error('Parsing error', data);
cb({ error: 'Impossible de récupérer la liste des établissements' });
return;
}
cb({ success: true, data });
});
});
rq.write(qs.stringify({
data: JSON.stringify({
nomFonction: 'geoLoc',
lat,
long,
}),
}));
rq.end();
};