-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbart-api.js
51 lines (44 loc) · 1.34 KB
/
bart-api.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
var _ = require('underscore');
var express = require('express');
var http = require('http');
var xml2js = require('xml2js');
var Bart = require('bart-api');
var bart = new Bart('MW9S-E7SL-26DU-VV8V');
bart.sched.arrive({
orig: 'SFIA',
dest: 'PITT'
}, function (err, xml, body) {
if (err) {
throw err;
}
var trips = [];
xml.find('/root/schedule/request/trip').forEach(function (trip) {
trips.push({
orig: trip.attr('origin').value(),
dest: trip.attr('destination').value(),
times: {
orig: trip.attr('origTimeMin').value(),
dest: trip.attr('destTimeMin').value()
},
legs: trip.find('leg').map(function (leg) {
return {
orig: leg.attr('origin').value(),
dest: leg.attr('destination').value(),
line: leg.attr('line').value(),
head: leg.attr('trainHeadStation').value(),
times: {
orig: leg.attr('origTimeMin').value(),
dest: leg.attr('destTimeMin').value()
}
};
})
})
});
console.log(JSON.stringify(trips, true, 2));
});
bartApp.get('/', function (req, res) {
res.sendfile(__dirname + '/public/index.html');
});
var server = bartApp.listen(3000, function(){
console.log('Listening on port %d', server.address().port);
});