derhuerst / hafas-departures-in-direction

[obsolete] – Pass in a HAFAS client, get departures in a certain direction.
https://github.com/derhuerst/hafas-departures-in-direction#hafas-departures-in-direction
ISC License
0 stars 0 forks source link
departures public-transport transit vbb

hafas-departures-in-direction

Pass in a hafas-client-compatible HAFAS API client and get departures at a station in a certain direction.

Note: This library is obsolete because hafas-client now supports querying departures by direction. Use it directly or hafas-collect-departures-at to collect departures with any termination logic.

No Maintenance Intended npm version build status ISC-licensed

Installing

npm install hafas-departures-in-direction

Usage

Pass in your hafas-client-compatible HAFAS API client. In this case, we're going to use vbb-hafas:

const setup = require('hafas-departures-in-direction')
const hafas = require('vbb-hafas')

const depsInDirection = setup(hafas.departures, hafas.journeyLeg)

Specify the direction as the next station after the one you're querying departures for. depsInDirection will then query departures, advancing in time until it found enough results or sent enough requests.

const friedrichstr = '900000100001' // where to get departures
const brandenburgerTor = '900000100025' // direction

depsInDirection(friedrichstr, brandenburgerTor)
.then(console.log)
.catch(console.error)

The results will look similar to those of hafas-client.

API

depsInDirection = setup(fetchDepartures, fetchJourneyLeg)

fetchDepartures(stationId, opt) should be API-compatible with hafas-client.departures. fetchJourneyLeg(ref, lineName, opt) should be API-compatible with hafas-client.journeyLeg. Both should return valid FPTF 1.1.1.

depsInDirection(station, direction, [opt])

opt overrides the following defaults:

{
    concurrency: 4, // max nr. of parallel requests
    results: 10, // nr. of results to collect
    maxQueries: 10, // max nr. of requests
    when: null // time in ms since epoch
}

Returns a Promise that resolves with an array of departures.