From 542a9eea0253db658c27d7dcd6b8636e68de6601 Mon Sep 17 00:00:00 2001 From: Simeon Keske Date: Thu, 6 Feb 2020 16:25:21 +0100 Subject: [PATCH] add VSN profile --- p/vsn/example.js | 47 ++++++++++++++++++++++++++ p/vsn/index.js | 37 +++++++++++++++++++++ p/vsn/products.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++ p/vsn/readme.md | 14 ++++++++ readme.md | 1 + 5 files changed, 183 insertions(+) create mode 100644 p/vsn/example.js create mode 100644 p/vsn/index.js create mode 100644 p/vsn/products.js create mode 100644 p/vsn/readme.md diff --git a/p/vsn/example.js b/p/vsn/example.js new file mode 100644 index 00000000..30d613f2 --- /dev/null +++ b/p/vsn/example.js @@ -0,0 +1,47 @@ +'use strict' + +const createClient = require('../..') +const vsnProfile = require('.') + +const client = createClient(vsnProfile, 'hafas-client-example') + +// client.journeys('9033961', '9033962', {results: 1, polylines: true}) +// client.departures('9033961', {duration: 1}) +// client.arrivals('9033961', {duration: 10, linesOfStops: true}) +client.locations('jugendherberge', {results: 2}) +// client.stop('9033961', {linesOfStops: true}) +// client.nearby({ +// type: 'location', +// latitude: 53.554422, +// longitude: 9.977934 +// }, {distance: 60}) +// client.radar({ +// north: 53.55, +// west: 9.95, +// south: 52.51, +// east: 10 +// }, {results: 10}) +// client.reachableFrom({ +// type: 'location', +// address: 'Hamburg, Holstenwall 9', +// latitude: 53.553766, +// longitude: 9.977514 +// }, { +// when: new Date('2019-05-16T10:00:00+0200'), +// maxDuration: 8 +// }) + +// .then(({journeys}) => { +// const [journey] = journeys +// const leg = journey.legs[0] +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) + +// .then(({journeys}) => { +// const [journey] = journeys +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/vsn/index.js b/p/vsn/index.js new file mode 100644 index 00000000..f029a707 --- /dev/null +++ b/p/vsn/index.js @@ -0,0 +1,37 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = {type: 'IPA', id: 'VSN', name: 'vsn', v: '5030100', os: 'iOS 13.3'} + body.ver = '1.24' + body.auth = {type: 'AID', aid: 'Mpf5UPC0DmzV8jkg'} + body.lang = 'de' + + return body +} + +const vsnProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://fahrplaner.vsninfo.de/hafas/mgate.exe', + + // https://gist.github.com/n0emis/3b6887572793f4f54da9d83b30548332#file-haf_config_base-properties-L31 + // https://runkit.com/derhuerst/hafas-decrypt-encrypted-mac-salt + salt: Buffer.from('535033316d4275665379434c6d4e7870', 'hex'), + addMicMac: true, + + transformReqBody, + + products: products, + + trip: true, + radar: true, + refreshJourney: true, + reachableFrom: true, + + departuresGetPasslist: false, + departuresStbFltrEquiv: false +} + +module.exports = vsnProfile diff --git a/p/vsn/products.js b/p/vsn/products.js new file mode 100644 index 00000000..f2e064fa --- /dev/null +++ b/p/vsn/products.js @@ -0,0 +1,84 @@ +'use strict' + +module.exports = [ + { + id: 'nationalExpress', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress', + short: 'ICE', + default: true + }, + { + id: 'national', + mode: 'train', + bitmasks: [2], + name: 'Fernzug', + short: 'IC/EC/CNL', + default: true + }, + { + id: 'regionalExpress', + mode: 'train', + bitmasks: [4], + name: 'RegionalExpress & InterRegio', + short: 'RE/IR', + default: true + }, + { + id: 'regional', + mode: 'train', + bitmasks: [8], + name: 'Nahverhehr', + short: 'NV', + default: true + }, + { + id: 'suburban', + mode: 'train', + bitmasks: [16], + name: 'S-Bahn', + short: 'S', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'Bus', + short: 'Bus', + default: true + }, + { + id: 'ferry', + mode: 'watercraft', + bitmasks: [64], + name: 'Schiff', + short: 'F', + default: true + }, + { + id: 'subway', + mode: 'train', + bitmasks: [128], + name: 'U-Bahn', + short: 'U', + default: true + }, + { + id: 'tram', + mode: 'train', + bitmasks: [256], + name: 'Straßen-/Stadtbahn', + short: 'T', + default: true + }, + { + id: 'anrufSammelTaxi', + mode: 'taxi', + bitmasks: [512], + name: 'Anruf-Sammel-Taxi', + short: 'AST', + default: true + }, +] diff --git a/p/vsn/readme.md b/p/vsn/readme.md new file mode 100644 index 00000000..4db240d6 --- /dev/null +++ b/p/vsn/readme.md @@ -0,0 +1,14 @@ +# VSN profile for `hafas-client` +[*Verkehrsverbund Süd-Niedersachsen (VSN)*](https://de.wikipedia.org/wiki/Verkehrsverbund_S%C3%BCd-Niedersachsen) is the local transport provider south [Lower Saxony](https://en.wikipedia.org/wiki/Lower_Saxony). This profile adds *VSN*-specific customizations to `hafas-client`. + +## Usage +```js +const createClient = require('hafas-client') +const vsnProfile = require('hafas-client/p/vsn') + +// create a client with VSN profile +const client = createClient(vsnProfile, 'my-awesome-program') +``` + +## Customisations +- parses *VSN*-specific products diff --git a/readme.md b/readme.md index e5bc3f26..6fb6f5e3 100644 --- a/readme.md +++ b/readme.md @@ -206,6 +206,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [Hamburg public transport (HVV)](https://en.wikipedia.org/wiki/Hamburger_Verkehrsverbund) | - | [docs](p/hvv/readme.md) | [example code](p/hvv/example.js) | [src](p/hvv/index.js) [*Nordhessischer Verkehrsverbund (NVV)*](https://en.wikipedia.org/wiki/Nordhessischer_Verkehrsverbund) ([Hesse](https://en.wikipedia.org/wiki/Hesse)) | - | [docs](p/nvv/readme.md) | [example code](p/nvv/example.js) | [src](p/nvv/index.js) *DB Busradar NRW* ([DB Regio Bus](https://en.wikipedia.org/wiki/DB_Regio#Bus_division_(DB_Regio_Bus))) | - | [docs](p/db-busradar-nrw/readme.md) | [example code](p/db-busradar-nrw/example.js) | [src](p/db-busradar-nrw/index.js) +[Verkehrsverbund Süd-Niedersachsen (VSN)](https://de.wikipedia.org/wiki/Verkehrsverbund_S%C3%BCd-Niedersachsen) | - | [docs](p/vsn/readme.md) | [example code](p/vsn/example.js) | [src](p/vsn/index.js) There are also libraries that use `hafas-client` and pass their own profile in: