mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parent
18f8c81b59
commit
7444e08819
5 changed files with 191 additions and 0 deletions
46
p/sbb/example.js
Normal file
46
p/sbb/example.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const createClient = require('../../')
|
||||||
|
const sbbProfile = require('.')
|
||||||
|
|
||||||
|
const client = createClient(sbbProfile, 'hafas-client-example')
|
||||||
|
|
||||||
|
const zurich1 = '8530813' // Zürich Kreuzplatz
|
||||||
|
const zurich2 = '8503000' // Zürich HB
|
||||||
|
const basel1 = '8500073' // Basel Aeschenplatz
|
||||||
|
const basel2 = '8500010' // Basel SBB
|
||||||
|
const baden1 = '8590197'
|
||||||
|
const baden2 = '8590173'
|
||||||
|
const locBaden = { type: 'location', latitude: 47.476, longitude: 8.30613 }
|
||||||
|
|
||||||
|
// client.journeys(zurich1, basel1, { results: 1 })
|
||||||
|
// client.journeys(zurich2, basel2, { results: 1 })
|
||||||
|
client.journeys(baden1, baden2, { results: 1 })
|
||||||
|
// client.departures(zurich2, {duration: 1})
|
||||||
|
// client.arrivals(zurich2, {duration: 10, linesOfStops: true})
|
||||||
|
// client.locations('Basel', { results: 2 })
|
||||||
|
// client.locations('Luzern', { poi: true, stops: false })
|
||||||
|
// client.stop(basel2)
|
||||||
|
// client.nearby(locBaden, { distance: 100 })
|
||||||
|
// client.radar({
|
||||||
|
// north: 47.5,
|
||||||
|
// west: 8.2,
|
||||||
|
// south: 47.3,
|
||||||
|
// east: 8.5,
|
||||||
|
// }, { results: 10 })
|
||||||
|
// client.reachableFrom({
|
||||||
|
// type: 'location',
|
||||||
|
// id: '980023031',
|
||||||
|
// latitude: 47.052417,
|
||||||
|
// longitude: 8.304487,
|
||||||
|
// name: 'Luzern, Adlun',
|
||||||
|
// poi: true
|
||||||
|
// }, {
|
||||||
|
// maxDuration: 20
|
||||||
|
// })
|
||||||
|
|
||||||
|
|
||||||
|
.then((data) => {
|
||||||
|
console.log(require('util').inspect(data, {depth: null, colors: true}))
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
36
p/sbb/index.js
Normal file
36
p/sbb/index.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const products = require('./products')
|
||||||
|
|
||||||
|
const transformReqBody = (ctx, body) => {
|
||||||
|
// sourced from https://github.com/marudor/BahnhofsAbfahrten/blob/1c99d8b/packages/server/HAFAS/profiles.ts#L344-L361
|
||||||
|
body.client = {
|
||||||
|
type: 'AND',
|
||||||
|
id: 'DBZUGRADARNETZ',
|
||||||
|
v: '',
|
||||||
|
}
|
||||||
|
body.ver = '1.18'
|
||||||
|
body.auth = { aid: 'hf7mcf9bv3nv8g5f', type:'AID' }
|
||||||
|
body.lang = 'deu'
|
||||||
|
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
|
const sbbProfile = {
|
||||||
|
locale: 'de-CH',
|
||||||
|
timezone: 'Europe/Zurich',
|
||||||
|
// todo: find a way to use https:
|
||||||
|
endpoint: 'http://fahrplan.sbb.ch/bin/mgate.exe',
|
||||||
|
transformReqBody,
|
||||||
|
|
||||||
|
products: products,
|
||||||
|
|
||||||
|
trip: true,
|
||||||
|
radar: true,
|
||||||
|
reachableFrom: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const withLocale = (locale) => ({...sbbProfile, locale})
|
||||||
|
|
||||||
|
sbbProfile.withLocale = withLocale
|
||||||
|
module.exports = sbbProfile
|
85
p/sbb/products.js
Normal file
85
p/sbb/products.js
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
id: 'express-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [1],
|
||||||
|
name: 'ICE/EN/CNL/ES/RJ/TGV/THA',
|
||||||
|
short: 'ICE/TGV/RJ',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'international-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [2],
|
||||||
|
name: 'EC/IC/ICN/OEC',
|
||||||
|
short: 'EC/IC',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'interregional-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [4],
|
||||||
|
name: 'IR/PE',
|
||||||
|
short: 'IR',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'regional-express-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [8],
|
||||||
|
name: 'RE/D',
|
||||||
|
short: 'RE',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'watercraft',
|
||||||
|
mode: 'watercraft',
|
||||||
|
bitmasks: [16],
|
||||||
|
name: 'Schiff/Fähre/Dampfschiff',
|
||||||
|
short: 'Schiff',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'suburban-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [32],
|
||||||
|
name: 'S/SN/R/TER/RB',
|
||||||
|
short: 'S',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'bus-taxi',
|
||||||
|
mode: 'bus',
|
||||||
|
bitmasks: [64],
|
||||||
|
name: 'Bus/Taxi',
|
||||||
|
short: 'Bus',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'gondola',
|
||||||
|
mode: 'gondola',
|
||||||
|
// e.g. `FUN 13` ("Gurtenbahn") at Gurten Kulm (ID `8507099`)
|
||||||
|
bitmasks: [128],
|
||||||
|
name: 'Standseilbahn/Gondelbahn/Luftseilbahn/Sesselbahn',
|
||||||
|
short: 'Seilbahn/Zahnradbahn',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'car-train',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [256], // todo: correct?
|
||||||
|
name: 'Autoreisezug/Extrazug',
|
||||||
|
short: 'ARZ/EXT',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'tram',
|
||||||
|
mode: 'train',
|
||||||
|
bitmasks: [512],
|
||||||
|
name: 'Tram/Metro',
|
||||||
|
short: 'Tram/Metro',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
]
|
23
p/sbb/readme.md
Normal file
23
p/sbb/readme.md
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# SBB profile for `hafas-client`
|
||||||
|
|
||||||
|
[*Schweizerische Bundesbahnen (SBB)*](https://en.wikipedia.org/wiki/Swiss_Federal_Railways) is the largest Swiss long-distance public transport company. This profile adds *SBB*-specific customizations to `hafas-client`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const createClient = require('hafas-client')
|
||||||
|
const sbbProfile = require('hafas-client/p/sbb')
|
||||||
|
|
||||||
|
// create a client with SBB profile
|
||||||
|
const client = createClient(sbbProfile, 'my-awesome-program')
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, the `de_CH` locale is being used. You can customize it using `withLocale()`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// create a client with SBB profile and fr_CH locale
|
||||||
|
const client = createClient(sbbProfile.withLocale('fr_CH'), 'my-awesome-program')
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Customisations
|
|
@ -206,6 +206,7 @@ Each of the [profiles](p) has more detailed example code.
|
||||||
HAFAS endpoint | wrapper library | docs | example code | source code
|
HAFAS endpoint | wrapper library | docs | example code | source code
|
||||||
---------------|------------------|------|---------|------------
|
---------------|------------------|------|---------|------------
|
||||||
[Deutsche Bahn (DB)](https://en.wikipedia.org/wiki/Deutsche_Bahn) | [`db-hafas`](https://github.com/public-transport/db-hafas) | [docs](p/db/readme.md) | [example code](p/db/example.js) | [src](p/db/index.js)
|
[Deutsche Bahn (DB)](https://en.wikipedia.org/wiki/Deutsche_Bahn) | [`db-hafas`](https://github.com/public-transport/db-hafas) | [docs](p/db/readme.md) | [example code](p/db/example.js) | [src](p/db/index.js)
|
||||||
|
[Swiss Railways (SBB)](https://en.wikipedia.org/wiki/Swiss_Federal_Railways) | - | [docs](p/sbb/readme.md) | [example code](p/sbb/example.js) | [src](p/sbb/index.js)
|
||||||
[Polskie Koleje Państwowe (PKP)](https://en.wikipedia.org/wiki/Polish_State_Railways) | [`pkp-hafas`](https://github.com/juliuste/pkp-hafas) | [docs](p/pkp/readme.md) | [example code](p/pkp/example.js) | [src](p/pkp/index.js)
|
[Polskie Koleje Państwowe (PKP)](https://en.wikipedia.org/wiki/Polish_State_Railways) | [`pkp-hafas`](https://github.com/juliuste/pkp-hafas) | [docs](p/pkp/readme.md) | [example code](p/pkp/example.js) | [src](p/pkp/index.js)
|
||||||
[Belgian National Railways (SNCB/NMBS)](https://en.wikipedia.org/wiki/National_Railway_Company_of_Belgium) | - | [docs](p/sncb/readme.md) | [example code](p/sncb/example.js) | [src](p/sncb/index.js)
|
[Belgian National Railways (SNCB/NMBS)](https://en.wikipedia.org/wiki/National_Railway_Company_of_Belgium) | - | [docs](p/sncb/readme.md) | [example code](p/sncb/example.js) | [src](p/sncb/index.js)
|
||||||
[*Iarnród Éireann* (Irish Rail)](https://en.wikipedia.org/wiki/Iarnród_Éireann) | - | [docs](p/irish-rail/readme.md) | [example code](p/irish-rail/example.js) | [src](p/irish-rail/index.js)
|
[*Iarnród Éireann* (Irish Rail)](https://en.wikipedia.org/wiki/Iarnród_Éireann) | - | [docs](p/irish-rail/readme.md) | [example code](p/irish-rail/example.js) | [src](p/irish-rail/index.js)
|
||||||
|
|
Loading…
Add table
Reference in a new issue