This commit adapts parseWhen & parsePlatform to the latest FPTF v2 draft. see public-transport/friendly-public-transport-format#63 |
||
---|---|---|
docs | ||
format | ||
lib | ||
p | ||
parse | ||
test | ||
tools/debug-cli | ||
.appveyor.yml | ||
.editorconfig | ||
.gitignore | ||
.travis.yml | ||
index.js | ||
license.md | ||
package.json | ||
readme.md | ||
retry.js | ||
throttle.js |
hafas-client
A client for HAFAS public transport APIs. Sort of like public-transport-enabler, but with a smaller scope. It contains customisations for several public transportation networks
Background
There's a company called HaCon that sells a public transport management system called HAFAS. It is used by companies all over Europe to serve routing and departure information for apps. All those endpoints are similar, with the same terms and API routes, but have slightly different options, filters and sets of enabled features.
hafas-client
contains all logic for communicating with these, as well as serialising from and parsing to Friendly Public Transport Format (FPTF) 1.2.0
. Endpoint-specific customisations (called profiles here) increase the quality of the returned data.
Installing
npm install hafas-client
with react-native
hafas-client
as well its dependencies use Node-builtin modules and Node globals. To be able to use it within react-native, follow the instructions at node-libs-react-native
.
Usage
const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
// create a client with the Deutsche Bahn profile
const client = createClient(dbProfile, 'my-awesome-program')
// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1})
.then(console.log).catch(console.error)
journeys()
returns a Promise
that will resolve with an object with an array journeys
that contains one FPTF journey
.
{
journeys: [ {
origin: {
type: 'station',
id: '8089100',
name: 'Berlin Jungfernheide (S)',
location: { /* … */ },
products: { /* … */ }
},
departure: '2019-12-17T17:05:30+01:00',
departureDelay: 30,
departurePlatform: '5',
destination: {
type: 'station',
id: '8000261',
name: 'München Hbf',
location: { /* … */ },
products: { /* … */ }
},
arrival: '2019-12-17T22:44:00+01:00',
arrivalDelay: -60,
arrivalPlatform: '11A',
legs: [ {
id: '1|100067|48|81|17122017',
line: {
type: 'line',
id: '41172',
name: 'S 41',
public: true,
mode: 'train',
product: 'suburban',
operator: {
type: 'operator',
id: 's-bahn-berlin-gmbh',
name: 'S-Bahn Berlin GmbH'
}
},
direction: 'Ringbahn ->',
origin: {
type: 'station',
id: '8089100',
name: 'Berlin Jungfernheide (S)',
location: {
type: 'location',
latitude: 52.530291,
longitude: 13.299451
},
products: { /* … */ }
},
departure: '2019-12-17T17:05:30+01:00',
departureDelay: 30,
departurePlatform: '5',
destination: {
type: 'station',
id: '8089118',
name: 'Berlin Beusselstraße'
/* … */
},
arrival: '2019-12-17T17:08:00+01:00',
arrivalDelay: null,
arrivalPlatform: '2a-b'
},
/* more legs… */
{
walking: true,
public: true,
origin: {
type: 'station',
id: '730749',
name: 'Berlin Hauptbahnhof (S+U), Berlin'
/* … */
},
departure: '2019-12-17T17:25:00+01:00',
departureDelay: null,
destination: {
type: 'station',
id: '8098160',
name: 'Berlin Hbf (tief)'
/* … */
},
arrival: '2019-12-17T17:33:00+01:00',
arrivalDelay: null
}, {
id: '1|70906|0|81|17122017',
line: { /* … */ },
direction: 'München Hbf',
origin: {
type: 'station',
id: '8098160',
name: 'Berlin Hbf (tief)'
/* … */
},
departure: '2019-12-17T17:35:00+01:00',
departureDelay: -120,
departurePlatform: '1',
destination: {
type: 'station',
id: '8000261',
name: 'München Hbf',
/* … */
},
arrival: '2019-12-17T22:44:00+01:00',
arrivalDelay: -60,
arrivalPlatform: '11A'
} ],
price: {
amount: null,
hint: 'No pricing information available.'
}
/* … */
} ]
/* … */
}
API
supported networks/endpoints
hafas-client
has built-in customisations (called "profiles") for these public transportation networks:
There are also libraries that use hafas-client
and pass their own profile in:
HAFAS endpoint | library |
---|---|
Betriebsstellen & disturbances in the German rail network | db-netz-hafas |
Related
public-transport-enabler
– Unleash public transport data in your Java project.- Friendly Public Transport Format – A format for APIs, libraries and datasets containing and working with public transport data.
db-hafas
– JavaScript client for the DB HAFAS API.vbb-hafas
– JavaScript client for Berlin & Brandenburg public transport HAFAS API.observe-hafas-client
– Observe all departures/arrivals/etc. returned byhafas-client
.cached-hafas-client
– Pass in ahafas-client
instance, cache data from it.hafas-client-rpc
– Make JSON-RPC calls tohafas-client
via WebSockets & stdio.hafas-client-health-check
– Check if ahafas-client
instance and its endpoint work.hafas-rest-api
– Expose a HAFAS client via an HTTP REST API.- List of european long-distance transport operators, available API endpoints, GTFS feeds and client modules.
- Collection of european transport JavaScript modules.
hafas-collect-departures-at
– Utility to collect departures, using any HAFAS client.hafas-monitor-trips
– Using a HAFAS client, watch all trips in a bounding box.hafas-monitor-departures
– Pass in a HAFAS client, fetch all departures at any set of stations.hafas-record-delays
– Record delays fromhafas-monitor-departures
into a LevelDB.hafas-monitor-journeys
– Usehafas-client
to monitor journeys from A to B.hafas-discover-stations
– Pass in a HAFAS client, discover stations by querying departures.hafas-estimate-station-weight
– Pass in a HAFAS client, estimate the importance of a station.
Contributing
If you have a question, found a bug or want to propose a feature, have a look at the issues page.