-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·57 lines (51 loc) · 1.19 KB
/
cli.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
#!/usr/bin/env node
require('dotenv').config()
const NSAPI = require('ns-api');
const moment = require('moment');
const [, , ...args] = process.argv
if(!args.length) {
console.log('usage: departures [station]');
return;
}
const ns = new NSAPI({
key: process.env.API_KEY,
});
var stations = {
'utrecht': 'UT',
'amsterdam': 'ASD',
'ede':'ED'
};
ns.getDepartures({
station: stations[args[0]],
maxJourneys: 25,
})
.then(data => data.map(function (d) {
return {
richting: d.direction,
vertrek: moment(d.actualDateTime).format("HH:mm"),
spoor: d.plannedTrack,
soort: d.trainCategory
}
}))
.then(data => data.sort(function (a, b) {
if (a[1] === b[1]) {
return 0;
}
else {
return (a[1] < b[1]) ? -1 : 1;
}
}))
.then(data => console.table(data, ['richting', 'vertrek', 'spoor', 'soort']))
.catch(console.error)
;
// ns.getAllStations()
// .then (data => data.filter (station => station.land === 'NL'))
// .then (data => data.map(function (d) {
// return {
// code: d.code,
// naam: d.namen.lang
// };
// }))
// .then (data => console.table (data, ['code', 'naam']))
// .catch (console.error)
// ;