-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
195 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
repo_token: LEm8hxR9pZEiSy9zY0cQvlPi4wi9LfgpV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
- "lts/*" | ||
- "node" | ||
|
||
notifications: | ||
email: false | ||
|
||
after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage | ||
script: npm run coverage | ||
|
||
after_success: 'npm run coveralls' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,81 @@ | ||
'use strict'; | ||
|
||
var find = require('./find'); | ||
var requestP = require('request-promise'); | ||
var utils = require('./utils'); | ||
var bluebird = require('bluebird'); | ||
|
||
var monitor = function monitor(stop, offset, amount, callback) { | ||
// remove whitespace, vvo-online.de handles all kinds of requests pretty nicely | ||
stop = utils.stripSpaces(stop); | ||
function depatureMonitor(stopid, offset, amount) { | ||
|
||
var now = new Date(); | ||
var time = now; | ||
if (offset !== 'undefined' && offset !== 0) | ||
time = new Date(now.getTime() + (offset * 60 * 1000)); | ||
|
||
// hst = name of bus- or tramstop, e.g. 'Helmholtzstraße' | ||
// vz = time offset from now; trims the beginning of the array | ||
// lim = limit the amount of results, max seems to be 31 | ||
// var url = 'http://widgets.vvo-online.de/abfahrtsmonitor/Abfahrten.do?hst=' + stop + '&vz=' + offset + '&lim=' + amount; | ||
var options = { | ||
url: 'http://widgets.vvo-online.de/abfahrtsmonitor/Abfahrten.do', | ||
url: 'https://webapi.vvo-online.de/dm?format=json', | ||
qs: { | ||
hst: stop, | ||
vz: offset, | ||
lim: amount | ||
stopid: stopid, | ||
time: time.toISOString(), | ||
isarrival: false, | ||
limit: amount, | ||
shorttermchanges: true, | ||
mentzonly: false | ||
} | ||
}; | ||
|
||
var now = new Date(); | ||
|
||
return requestP(options) | ||
.then(JSON.parse) | ||
.map(function (transport) { | ||
var arrivalTimeRelative = parseInt(transport[2]) || 0; | ||
return { | ||
line: transport[0], | ||
direction: transport[1], | ||
arrivalTimeRelative: arrivalTimeRelative, | ||
arrivalTime: new Date(now.getTime() + 60000 * arrivalTimeRelative), | ||
mode: utils.parseMode(transport[0]) | ||
}; | ||
}).nodeify(callback); | ||
.then(function (data) { | ||
// check status | ||
if (data.Status && | ||
data.Status.Code == 'Ok' && | ||
data.Departures) { | ||
|
||
return data.Departures.map(function (d) { | ||
var arrivalTime = d.RealTime ? d.RealTime.match(/\d+/)[0] : d.ScheduledTime.match(/\d+/)[0]; | ||
arrivalTime = new Date(1 * arrivalTime); | ||
var scheduledTime = new Date(1 * d.ScheduledTime.match(/\d+/)[0]); | ||
|
||
return { | ||
line: d.LineName, | ||
direction: d.Direction, | ||
platform: d.Platform ? parseInt(d.Platform.Name) : undefined, | ||
arrivalTime: arrivalTime, | ||
arrivalTimeRelative: Math.round((arrivalTime - now) / 6e4), | ||
scheduledTime: scheduledTime, | ||
scheduledTimeRelative: Math.round((scheduledTime - now) / 6e4), | ||
delayTime: Math.round((arrivalTime - scheduledTime) / 6e4), | ||
state: d.State ? d.State : 'Unknown', | ||
mode: utils.parseMot(d.Mot) | ||
}; | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
var monitor = function monitor(stop, offset, amount, callback) { | ||
var stopPromise; | ||
|
||
if (typeof(stop) === 'string') { | ||
stopPromise = find(utils.stripSpaces(stop)) | ||
.then(function (stops) { | ||
if (!stops || stops.length == 0) | ||
throw new Error('no stops found'); | ||
return stops[0].id; | ||
}); | ||
} else { | ||
stopPromise = bluebird.resolve(stop); | ||
} | ||
|
||
return stopPromise | ||
.then(function (stop) { | ||
return depatureMonitor(stop, offset, amount); | ||
}) | ||
.catch(function () { | ||
return []; | ||
}) | ||
.nodeify(callback); | ||
}; | ||
|
||
module.exports = monitor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"5656699|4621216" | ||
"5656699|4621216" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"0" }, { "name":"sessionID", "value":"0" } ], "stopFinder": { "message": [ { "name":"code", "value":"-2000" }, { "name":"error", "value":"stop invalid" } ], "input": { "input":"0" }, "points": null } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "parameters": [ { "name":"serverID", "value":"efa.vvo-online.de:8080" }, { "name":"requestID", "value":"0" }, { "name":"sessionID", "value":"0" } ], "stopFinder": { "input": { "input":"Postpl" }, "points": { "point": { "usage":"sf", "type":"stop", "name":"Dresden, Postplatz", "stateless":"33000037", "ref": { "id":"33000037", "omc":"14612000", "placeID":"1", "place":"Dresden", "coords":"13.733513736,51.050834998" }, "infos": null } } } } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Name":"Postplatz","Status":{"Code":"Ok"},"Place":"Dresden","ExpirationTime":"\/Date(1487292603015+0100)\/","Departures":[{"Id":"65501116","LineName":"62","Direction":"Gompitz","Platform":{"Name":"3","Type":"Platform"},"Mot":"CityBus","RealTime":"\/Date(1487294700000+0100)\/","ScheduledTime":"\/Date(1487294700000+0100)\/","State":"InTime","RouteChanges":["509223"],"Diva":{"Number":"21062","Network":"voe"}},{"Id":"65499188","LineName":"7","Direction":"Pennrich","Platform":{"Name":"4","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487294700000+0100)\/","ScheduledTime":"\/Date(1487294700000+0100)\/","State":"InTime","Diva":{"Number":"11007","Network":"voe"}},{"Id":"65501226","LineName":"62","Direction":"Pillnitz","Platform":{"Name":"4","Type":"Platform"},"Mot":"CityBus","RealTime":"\/Date(1487294700000+0100)\/","ScheduledTime":"\/Date(1487294700000+0100)\/","State":"InTime","RouteChanges":["509223"],"Diva":{"Number":"21062","Network":"voe"}},{"Id":"65498389","LineName":"2","Direction":"Kleinzschachwitz","Platform":{"Name":"1","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487294700000+0100)\/","ScheduledTime":"\/Date(1487294700000+0100)\/","State":"InTime","Diva":{"Number":"11002","Network":"voe"}},{"Id":"65499315","LineName":"7","Direction":"Weixdorf","Platform":{"Name":"3","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487294700000+0100)\/","ScheduledTime":"\/Date(1487294700000+0100)\/","State":"InTime","Diva":{"Number":"11007","Network":"voe"}}]} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.