npm

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

hafas-monitor-departures

2.2.1 • 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 hafas = createHafas('my-awesome-program')
const departures = createMonitor(hafas, stations, interval)
.on('error', console.error)
.on('data', console.log)
 
setTimeout(() => {
    departures.stop() // stop querying
}, interval * 3)

createMonitor will call hafas.departures() and writes each of the returned departures into the stream. It expects departures() to be compatible with the implementation from hafas-client.

Note: A stream created by calling createMonitor(…) does not stop calling the API if you unpipe it. You need to manually call departures.stop().

To manually issue a single departures check at a station, use departures.manual(id). The result will be emitted in a data event like all others.

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

23

version

2.2.1

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability