Pass in a HAFAS client, fetch all departures at any set of stations. (You may get blacklisted.)
If you want to monitor trips/departures in an area, use hafas-monitor-trips
. It polls HAFAS more efficiently.
npm install hafas-monitor-departures
As an exampe, we're going to use vbb-hafas
, the HAFAS client for Berlin.
const createMonitor = require('hafas-monitor-departures')
const createHafas = require('vbb-hafas')
const stations = ['900000100003'] // array of station ids
const interval = 2 * 60 * 1000 // every two minutes
const duration = 10 // each time, fetch departures for the next 10 min
const hafas = createHafas('my-awesome-program')
const monitor = createMonitor(hafas, stations, {interval, duration})
monitor.on('error', console.error)
monitor.on('departure', console.log)
setTimeout(() => {
monitor.removeListener('departure', console.log)
}, interval * 3)
hafas.departures()
must be compatible with the implementation of hafas-client@5
(or of hafas-client@^4
).
Once you listen to any of the departure
or stats
events, it will automatically start to watch, and stop once you stop listening.
To manually issue a single departures check at a station, use monitor.manual(id)
. The result will be emitted in a data event like all others.
createMonitor(hafasClient, listOfStations, opt = {})
opt
overrides the following default values:
{
interval: interval || 60 * 1000,
step: step || Math.floor(interval / stations.length),
duration: duration || Math.ceil(interval / 60 / 1000)
}
hafas-record-delays
– Record delays fromhafas-monitor-departures
into a LevelDB.record-vbb-delays
– Record VBB departures from HAFAS.hafas-monitor-trips
– Using a HAFAS endpoint, watch all trips in a bounding box.hafas-monitor-trips-server
– A server that manageshafas-monitor-trips
instances.hafas-client
– JavaScript client for HAFAS public transport APIs.
If you have a question, found a bug or want to propose a feature, have a look at the issues page.