From 1b941dea167822ba4e0407eede5e76d74e593eb3 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 28 Dec 2018 15:52:29 +0100 Subject: [PATCH] Saarfahrplan profile --- p/saarfahrplan/example.js | 43 ++++++++++++++++++ p/saarfahrplan/index.js | 37 +++++++++++++++ p/saarfahrplan/products.js | 93 ++++++++++++++++++++++++++++++++++++++ p/saarfahrplan/readme.md | 18 ++++++++ readme.md | 1 + 5 files changed, 192 insertions(+) create mode 100644 p/saarfahrplan/example.js create mode 100644 p/saarfahrplan/index.js create mode 100644 p/saarfahrplan/products.js create mode 100644 p/saarfahrplan/readme.md diff --git a/p/saarfahrplan/example.js b/p/saarfahrplan/example.js new file mode 100644 index 00000000..413dfa51 --- /dev/null +++ b/p/saarfahrplan/example.js @@ -0,0 +1,43 @@ +'use strict' + +const createClient = require('../..') +const saarfahrplanProfile = require('.') + +const client = createClient(saarfahrplanProfile, 'hafas-client-example') + +client.journeys('15541', '10609', {results: 1}) +// .then(([journey]) => { +// const leg = journey.legs[0] +// return client.trip(leg.id, leg.line.name, {polyline: true}) +// }) +// .then(([journey]) => { +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) + +// client.departures('15541', {duration: 1}) +// client.arrivals('15541', {duration: 10, stationLines: true}) +// client.locations('uhlandstr', {results: 2}) +// client.station('10609') // Uhlandstr., Saarbrücken +// client.nearby({ +// type: 'location', +// latitude: 49.229498, +// longitude: 7.008609 +// }, {distance: 400}) +// client.radar({ +// north: 49.244044, +// west: 6.987644, +// south: 49.235332, +// east: 7.006480 +// }, {results: 10}) +// client.reachableFrom({ +// type: 'location', +// id: '009000763', +// latitude: 49.235223, +// longitude: 6.996493, +// name: 'Saarbrücken, Rathaus' +// }, {maxDuration: 20}) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/saarfahrplan/index.js b/p/saarfahrplan/index.js new file mode 100644 index 00000000..a821952c --- /dev/null +++ b/p/saarfahrplan/index.js @@ -0,0 +1,37 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (body) => { + body.client = { + type: 'AND', + id: 'ZPS-SAAR', + v: 1000070, + name: 'Saarfahrplan', + os: 'Android 9' + } + body.ver = '1.21' + body.auth = {type: 'AID', aid: '51XfsVqgbdA6oXzHrx75jhlocRg6Xe'} + body.lang = 'de' + + return body +} + +const saarfahrplanProfile = { + locale: 'de-DE', + timezone: 'Europe/Berlin', + endpoint: 'https://saarfahrplan.de/bin/mgate.exe', + transformReqBody, + + // decrypted form of https://gist.github.com/derhuerst/f5a8c07f9b3226ecad6c8f64d83df6a2#file-haf_config_base-properties-L70 + salt: Buffer.from('HJtlubisvxiJxss', 'utf8'), + addMicMac: true, + + products: products, + + trip: true, + radar: true, + reachableFrom: true +} + +module.exports = saarfahrplanProfile diff --git a/p/saarfahrplan/products.js b/p/saarfahrplan/products.js new file mode 100644 index 00000000..995cb5f3 --- /dev/null +++ b/p/saarfahrplan/products.js @@ -0,0 +1,93 @@ +'use strict' + +module.exports = [ + { + id: 'nationalExpress', + mode: 'train', + bitmasks: [8192], + name: 'Hochgeschwindigkeitszug', + short: 'ICE', + default: true + }, + { + id: 'national', + mode: 'train', + bitmasks: [4096], + name: 'InterCity & EuroCity', + short: 'IC/EC', + default: true + }, + { + id: 'interregional', + mode: 'train', + bitmasks: [2048], + name: 'InterRegio', + short: 'IR', + default: true + }, + { + id: 'regional', + mode: 'train', + bitmasks: [1024], + name: 'Regionalzug', + short: 'RB ?', // todo + default: true + }, + { + id: 'suburban', + mode: 'train', + bitmasks: [512], + name: 'S-Bahn', + short: 'S-Bahn', + default: true + }, + { + id: 'subway', + mode: 'train', + bitmasks: [256], + name: 'U-Bahn', + short: 'U', + default: true + }, + { + id: 'saarbahn', + mode: 'train', + bitmasks: [128], + name: 'Saarbahn', + short: 'S', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [64], + name: 'Bus', + short: 'Bus', + default: true + }, + { + id: 'watercraft', + mode: 'watercraft', + bitmasks: [32], // todo: correct? + name: 'Schiff', + short: 'Schiff', + default: true + }, + { + id: 'onCall', + mode: null, // todo + bitmasks: [16], + name: 'Anruf-Sammel-Taxi', + short: 'AST', + default: true + }, + { + id: 'school-bus', + mode: 'bus', + bitmasks: [8], + name: 'Schulbus', + short: 'Schulbus', + default: true + } + // todo: `1`, `2`, `4` bitmasks? +] diff --git a/p/saarfahrplan/readme.md b/p/saarfahrplan/readme.md new file mode 100644 index 00000000..0c32e4dd --- /dev/null +++ b/p/saarfahrplan/readme.md @@ -0,0 +1,18 @@ +# Saarfahrplan profile for `hafas-client` + +*Saarfahrplan* is the public transport information system in [Saarland](https://en.wikipedia.org/wiki/Saarland). This profile adds *Saarfahrplan*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const saarfahrplanProfile = require('hafas-client/p/saarfahrplan') + +// create a client with Saarfahrplan profile +const client = createClient(saarfahrplanProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *Saarfahrplan*-specific products (such as *Saarbahn*) diff --git a/readme.md b/readme.md index 4908a5a4..5518d4c8 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,7 @@ HAFAS endpoint | wrapper library | docs | example code | source code [Nahverkehrsverbund Schleswig-Holstein (NAH.SH)](https://de.wikipedia.org/wiki/Nahverkehrsverbund_Schleswig-Holstein) | [`nahsh-hafas`](https://github.com/juliuste/nahsh-hafas) | [docs](p/nahsh/readme.md) | [example code](p/nahsh/example.js) | [src](p/nahsh/index.js) [Austin, Texas (CMTA/*CapMetro*)](https://en.wikipedia.org/wiki/Capital_Metropolitan_Transportation_Authority) | - | [docs](p/cmta/readme.md) | [example code](p/cmta/example.js) | [src](p/cmta/index.js) [*S-Bahn München*](https://en.wikipedia.org/wiki/Munich_S-Bahn) | - | [docs](p/sbahn-muenchen/readme.md) | [example code](p/sbahn-muenchen/example.js) | [src](p/sbahn-muenchen/index.js) +*Saarfahrplan* ([Saarland](https://en.wikipedia.org/wiki/Saarland)) | - | [docs](p/saarfahrplan/readme.md) | [example code](p/saarfahrplan/example.js) | [src](p/saarfahrplan/index.js) [![npm version](https://img.shields.io/npm/v/hafas-client.svg)](https://www.npmjs.com/package/hafas-client) [![build status](https://img.shields.io/travis/public-transport/hafas-client.svg?branch=master)](https://travis-ci.org/public-transport/hafas-client)