This repository has been archived by the owner on Nov 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiEAV.js
64 lines (60 loc) · 1.57 KB
/
apiEAV.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
const fetch = require('node-fetch');
const Fuse = require('fuse.js');
const querystring = require('querystring');
const config = require('./config');
function fetchStations () {
const { baseUrl } = config;
const formData = querystring.stringify({
id: '1'
});
const init = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
};
return fetch(`${baseUrl}/Home/DestinazioniFromStazione`, init);
}
function getInfoStation (station) {
return fetchStations()
.then((res) => res.json())
.then((json) => {
const options = {
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
'Descrizione'
]
};
const fuse = new Fuse(json, options);
const result = fuse.search(station);
return result;
});
}
function getTrip (date, stationArrival, time, stationDeparture) {
const { baseUrl } = config;
const formData = querystring.stringify({
data: date,
destinazione: stationArrival,
ora: `${time}:01`,
origine: stationDeparture
});
const init = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
};
return fetch(`${baseUrl}/Home/Create`, init);
}
module.exports.fetchStations = fetchStations;
module.exports.getInfoStation = getInfoStation;
module.exports.getTrip = getTrip;