From 4d0605737f2924abbea3dda040ef530bd639f643 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 12 Apr 2018 22:14:30 +0200 Subject: [PATCH] Rejseplanen profile --- p/rejseplanen/example.js | 34 ++++++++++++++++++++++++++++++ p/rejseplanen/index.js | 28 +++++++++++++++++++++++++ p/rejseplanen/products.js | 44 +++++++++++++++++++++++++++++++++++++++ p/rejseplanen/readme.md | 18 ++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 p/rejseplanen/example.js create mode 100644 p/rejseplanen/index.js create mode 100644 p/rejseplanen/products.js create mode 100644 p/rejseplanen/readme.md diff --git a/p/rejseplanen/example.js b/p/rejseplanen/example.js new file mode 100644 index 00000000..f9bd9637 --- /dev/null +++ b/p/rejseplanen/example.js @@ -0,0 +1,34 @@ +'use strict' + +const createClient = require('../..') +const rejseplanenProfile = require('.') + +const client = createClient(rejseplanenProfile, 'hafas-client-example') + +// from København Central to Aalborg +// client.journeys('8600626', '8600020', {results: 1}) +// .then(({journeys}) => { + +// const leg = journeys[0].legs[0] +// return client.trip(leg.tripId, leg.line.name) +// }) + +client.departures('8600626', {duration: 5}) +// client.locations('KØbenhaven', {results: 2}) +// client.stop('8600626') // København Central +// client.nearby({ +// type: 'location', +// latitude: 55.673, +// longitude: 12.566 +// }, {distance: 200}) +// client.radar({ +// north: 55.673, +// west: 12.566, +// south: 55.672, +// east: 12.567 +// }, {results: 10}) + +.then(data => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/rejseplanen/index.js b/p/rejseplanen/index.js new file mode 100644 index 00000000..348bf1e8 --- /dev/null +++ b/p/rejseplanen/index.js @@ -0,0 +1,28 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.ext = 'DK.9' + body.client = {type: 'AND', id: 'DK'} + body.ver = '1.21' + body.auth = {type: 'AID', aid: 'irkmpm9mdznstenr-android'} + + return body +} + +const rejseplanenProfile = { + locale: 'da-DK', + timezone: 'Europe/Copenhagen', + endpoint: 'https://mobilapps.rejseplanen.dk/bin/iphone.exe', + transformReqBody, + + products: products, + + departuresGetPasslist: false, + departuresStbFltrEquiv: false, + trip: true, + radar: true, +} + +module.exports = rejseplanenProfile; diff --git a/p/rejseplanen/products.js b/p/rejseplanen/products.js new file mode 100644 index 00000000..451195e4 --- /dev/null +++ b/p/rejseplanen/products.js @@ -0,0 +1,44 @@ +'use strict' + +module.exports = [ + { + id: 'national-train', + mode: 'train', + bitmasks: [1], + name: 'InterCity', + short: 'IC', + default: true, + }, + { + id: 'national-train-2', + mode: 'train', + bitmasks: [2], + name: 'ICL', // todo: find proper name + short: 'ICL', + default: true, + }, + { + id: 'local-train', + mode: 'train', + bitmasks: [4], + name: 'Regional', + short: 'RE', + default: true, + }, + { + id: 'o', + mode: 'train', // todo: correct? + bitmasks: [8], + name: 'Ø', // todo: find proper name + short: 'Ø', + default: true, + }, + { + id: 's-tog', + mode: 'train', + bitmasks: [16], + name: 'S-Tog A/B/Bx/C/E/F/H', + short: 'S', + default: true, + } +] diff --git a/p/rejseplanen/readme.md b/p/rejseplanen/readme.md new file mode 100644 index 00000000..20958b3a --- /dev/null +++ b/p/rejseplanen/readme.md @@ -0,0 +1,18 @@ +# Rejseplanen profile for `hafas-client` + +[*Rejseplanen*](https://da.wikipedia.org/wiki/Rejseplanen) is a Danish website for finding public transport connections throughout Denmark. This profile adds *Rejseplanen*-specific customisations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const rejseplanenProfile = require('hafas-client/p/rejseplanen') + +// create a client with Rejseplanen profile +const client = createClient(rejseplanenProfile) +``` + + +## Customisations + +- parses Denmark-specific products (such as *S-Tog*)