add ZVV profile

This commit is contained in:
Jannis R 2020-07-20 17:35:32 +02:00 committed by Jannis Redmann
parent e18fa7ccae
commit b2b1b75f04
5 changed files with 157 additions and 0 deletions

46
p/zvv/example.js Normal file
View file

@ -0,0 +1,46 @@
'use strict'
const createClient = require('../..')
const zvvProfile = require('.')
const client = createClient(zvvProfile, 'hafas-client-example')
const bürkliplatz = '8591105'
client.locations('bürkli', {results: 2})
// client.nearby({
// type: 'location',
// latitude: 47.366,
// longitude: 8.54,
// }, {distance: 60})
// client.journeys(bürkliplatz, '8591123', {results: 1, polylines: true})
// .then(({journeys}) => {
// const [journey] = journeys
// const leg = journey.legs[0]
// return client.trip(leg.tripId, leg.line.name, {polyline: true})
// })
// client.departures(bürkliplatz, {duration: 1})
// client.arrivals(bürkliplatz, {duration: 10, linesOfStops: true})
// client.stop(bürkliplatz, {linesOfStops: true}) // Dammtor
// client.radar({
// north: 47.387,
// west: 8.514,
// south: 47.356,
// east: 8.568,
// }, {results: 10})
// client.reachableFrom({
// type: 'location',
// address: 'Talstrasse',
// latitude: 47.366,
// longitude: 8.54,
// }, {
// when: new Date('2020-08-03T10:00:00+0200'),
// maxDuration: 8
// })
.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
})
.catch(console.error)

37
p/zvv/index.js Normal file
View file

@ -0,0 +1,37 @@
'use strict'
const products = require('./products')
const transformReqBody = (ctx, body) => {
body.client = {type: 'IPH', id: 'ZVV', name: 'zvvPROD-STORE', v: '6000400'}
body.ext = 'ZVV.2'
body.ver = '1.24'
body.auth = {type: 'AID', aid: 'TLRUqdDPF7ttB824Yoy2BN8mk'}
return body
}
const zvvProfile = {
locale: 'de-CH',
timezone: 'Europe/Zurich',
endpoint: 'https://online.fahrplan.zvv.ch/bin/mgate.exe',
// https://runkit.com/derhuerst/hafas-decrypt-encrypted-mac-salt
salt: Buffer.from('jCcZ864meuAbqGZ', 'utf-8'),
addMicMac: true,
transformReqBody,
products,
departuresGetPasslist: false,
departuresStbFltrEquiv: false,
trip: true,
radar: true,
// todo: fails with "Parser error: root.svcReqL.svcReqL.req(ctxRecon)"
refreshJourney: false,
reachableFrom: true,
}
module.exports = zvvProfile

60
p/zvv/products.js Normal file
View file

@ -0,0 +1,60 @@
'use strict'
module.exports = [
{
id: 'high-speed-train',
mode: 'train',
bitmasks: [1, 2, 4, 8],
name: 'High Speed Train',
short: 'High Speed',
default: true,
},
{
id: 'urban-train',
mode: 'train',
bitmasks: [32],
name: 'Urban Train',
short: 'Urban',
default: true,
},
{
id: 'tram',
mode: 'train',
bitmasks: [512],
name: 'Tram',
short: 'Tram',
default: true,
},
{
id: 'bus',
mode: 'bus',
bitmasks: [64],
name: 'Bus',
short: 'Bus',
default: true,
},
{
id: 'boat',
mode: 'watercraft',
bitmasks: [16],
name: 'Boat',
short: 'Boat',
default: true,
},
{
id: 'cable-car',
mode: 'gondola',
bitmasks: [128],
name: 'Cable Car',
short: 'Cable Car',
default: true,
},
{
id: 'night-train',
mode: 'train',
bitmasks: [256],
name: 'Night Train',
short: 'Night Train',
default: true,
},
]

13
p/zvv/readme.md Normal file
View file

@ -0,0 +1,13 @@
# ZVV profile for `hafas-client`
[*Zürcher Verkehrsverbund (ZVV)*](https://en.wikipedia.org/wiki/Zürcher_Verkehrsverbund) is the local transport system of [Zürich](https://en.wikipedia.org/wiki/Zürich). This profile adds *ZVV*-specific customizations to `hafas-client`.
## Usage
```js
const createClient = require('hafas-client')
const zvvProfile = require('hafas-client/p/zvv')
// create a client with ZVV profile
const client = createClient(zvvProfile, 'my-awesome-program')
```

View file

@ -227,6 +227,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code
[Rostocker Straßenbahn AG (RSAG)](https://de.wikipedia.org/wiki/Rostocker_Straßenbahn_AG) | - | [docs](p/rsag/readme.md) | [example code](p/rsag/example.js) | [src](p/rsag/index.js)
[Verkehrsverbund Mittelthüringen (VMT)](https://en.wikipedia.org/wiki/Verkehrsverbund_Mittelthüringen) | - | [docs](p/vmt/readme.md) | [example code](p/vmt/example.js) | [src](p/vmt/index.js)
[Salzburg public transport (SVV)](https://de.wikipedia.org/wiki/Salzburger_Verkehrsverbund) | - | [docs](p/svv/readme.md) | [example code](p/svv/example.js) | [src](p/svv/index.js)
[Zürich public transport (ZVV)](https://en.wikipedia.org/wiki/Zürcher_Verkehrsverbund) | - | [docs](p/zvv/readme.md) | [example code](p/zvv/example.js) | [src](p/zvv/index.js)
There are also libraries that use `hafas-client` and pass their own profile in: