This repository has been archived by the owner on Jan 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (75 loc) · 2.52 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
var request = require('request');
var parseString = require('xml2js').parseString;
// TODO: Error handling
var midttrafik =
{
getBuses: function(latitude, longitude, radius, callback)
{
var url = 'https://live.midttrafik.dk/getbuses.php?lat=' + latitude + '&lon=' + longitude + '&radius=' + radius;
request(url, function(err, response, body)
{
parseString(body, function(err, json_raw)
{
var json = json_raw.Result.Bus;
json = json.map(function(elem)
{
return elem.$;
});
// Output a JSON array of the busses found
callback(null, json);
});
});
},
getStops: function(latitude, longitude, radius, callback)
{
var url = 'https://live.midttrafik.dk/getstop.php?p=1&lat=' + latitude + '&lon=' + longitude + '&radius=' + radius;
request(url, function(err, response, body)
{
parseString(body, function(err, json_raw)
{
var json = json_raw.Result.Stop;
json = json.map(function(elem)
{
return elem.$;
});
// Output a JSON array of the busses found
callback(null, json);
});
});
},
getRouteStops: function(bus, callback)
{
var url = 'https://live.midttrafik.dk/getroutestops.php?p=1&journeyid=' + bus.JourneyId;
request(url, function(err, response, body)
{
parseString(body, function(err, json_raw)
{
var json = json_raw.Result.Stop;
json = json.map(function(elem)
{
return elem.$;
});
// Output a JSON array of the stops
callback(null, json);
});
});
},
getStopDepartures: function(stop, callback)
{
var url = 'https://live.midttrafik.dk/getstopinfo2.php?station=' + stop.Number + '&journeys=10';
request(url, function(err, response, body)
{
parseString(body, function(err, json_raw)
{
var json = json_raw.MultiDepartureBoard.Departure;
json = json.map(function(elem)
{
return elem.$;
});
// Output a JSON array of the stops
callback(null, json);
});
});
}
}
module.exports = midttrafik;