npm

Need private packages and team management tools?Check out npm Orgs. »

hafas-monitor-departures

3.0.0 • Public • Published

hafas-monitor-departures 🔭

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 version build status ISC-licensed gitter channel support me on Patreon

Installing

npm install hafas-monitor-departures

Usage

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 from hafas-client.

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.

API

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)
}

Related

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

install

npm i hafas-monitor-departures

Downloadsweekly downloads

15

version

3.0.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability