diff --git a/p/pkp/example.js b/p/pkp/example.js new file mode 100644 index 00000000..ef113854 --- /dev/null +++ b/p/pkp/example.js @@ -0,0 +1,46 @@ +'use strict' + +const createClient = require('../..') +const pkpProfile = require('.') + +const client = createClient(pkpProfile, 'hafas-client-example') + +const wrocławGł = '5100069' +const krakówGł = '5100028' + +client.journeys(krakówGł, wrocławGł, {results: 1, polylines: true}) +// client.departures(krakówGł, {duration: 10}) +// client.arrivals(krakówGł, {duration: 10, linesOfStops: true}) +// client.locations('kraków', {results: 2}) +// client.stop(krakówGł, {linesOfStops: true}) +// client.nearby({ +// type: 'location', +// latitude: 50.067192, +// longitude: 19.947423 +// }, {distance: 60}) +// client.radar({ +// north: 50.2, +// west: 19.8, +// south: 49.9, +// east: 20.1 +// }, {results: 10}) +// client.reachableFrom({ +// type: 'location', +// address: 'Bydgoszcz, Dworcowa 100', +// latitude: 53.1336648, +// longitude: 17.9908571 +// }, { +// when: new Date(), +// maxDuration: 20 +// }) + +// .then(({journeys}) => { +// const [journey] = journeys +// const leg = journey.legs[0] +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/pkp/index.js b/p/pkp/index.js new file mode 100644 index 00000000..2eaa95dd --- /dev/null +++ b/p/pkp/index.js @@ -0,0 +1,28 @@ +'use strict' + +const products = require('./products') + +const transformReqBody = (ctx, body) => { + body.client = {type: 'AND', id: 'HAFAS', name: 'Rozklad-PKP', v: '1000110'} + body.ver = '1.18' // 1.24 is used by the app, but that version doesn't support getPassList for departures/arrivals + body.auth = {type: 'AID', aid: 'DrxJYtYZQpEBCtcb'} + + return body +} + +const pkpProfile = { + locale: 'pl-PL', + timezone: 'Europe/Warsaw', + endpoint: 'https://mobil.rozklad-pkp.pl:8019/bin/mgate.exe', + + transformReqBody, + + products, + + trip: true, + radar: true, + refreshJourney: false, + reachableFrom: true +} + +module.exports = pkpProfile diff --git a/p/pkp/products.js b/p/pkp/products.js new file mode 100644 index 00000000..23e5f95b --- /dev/null +++ b/p/pkp/products.js @@ -0,0 +1,36 @@ +'use strict' + +module.exports = [ + { + id: 'high-speed-train', + mode: 'train', + bitmasks: [1, 2], + name: 'ExpressInterCity & ExpressInterCity Premium & InterCityExpress', + short: 'EIC/EIP/ICE', + default: true + }, + { + id: 'long-distance-train', + mode: 'train', + bitmasks: [4], + name: 'InterCity & Twoje Linie Kolejowe & EuroCity & EuroNight', + short: 'IC/TLK/EC/EN', + default: true + }, + { + id: 'regional-train', + mode: 'train', + bitmasks: [8], + name: 'Regional', + short: 'R', + default: true + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'Bus', + short: 'B', + default: true + } +] \ No newline at end of file diff --git a/p/pkp/readme.md b/p/pkp/readme.md new file mode 100644 index 00000000..3e71f9cd --- /dev/null +++ b/p/pkp/readme.md @@ -0,0 +1,18 @@ +# PKP profile for `hafas-client` + +[*Polskie Koleje Państwowe (PKP)*](https://en.wikipedia.org/wiki/Polish_State_Railways) is the major national transport provider in Poland. This profile adds *PKP*-specific customizations to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const pkpProfile = require('hafas-client/p/pkp') + +// create a client with PKP profile +const client = createClient(pkpProfile, 'my-awesome-program') +``` + + +## Customisations + +- parses *PKP*-specific products (such as *TLK*) diff --git a/readme.md b/readme.md index 5d3406c5..85259d1f 100644 --- a/readme.md +++ b/readme.md @@ -206,6 +206,7 @@ Each of the [profiles](p) has more detailed example 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/derhuerst/db-hafas) | [docs](p/db/readme.md) | [example code](p/db/example.js) | [src](p/db/index.js) +[Polskie Koleje Państwowe (PKP)](https://en.wikipedia.org/wiki/Polish_State_Railways) | - | [docs](p/pkp/readme.md) | [example code](p/pkp/example.js) | [src](p/pkp/index.js) [Berlin & Brandenburg public transport (VBB)](https://en.wikipedia.org/wiki/Verkehrsverbund_Berlin-Brandenburg) | [`vbb-hafas`](https://github.com/derhuerst/vbb-hafas) | [docs](p/vbb/readme.md) | [example code](p/vbb/example.js) | [src](p/vbb/index.js) [Berlin public transport (BVG)](https://en.wikipedia.org/wiki/Berliner_Verkehrsbetriebe) | [`bvg-hafas`](https://github.com/derhuerst/bvg-hafas) | [docs](p/bvg/readme.md) | [example code](p/bvg/example.js) | [src](p/bvg/index.js) [Österreichische Bundesbahnen (ÖBB)](https://en.wikipedia.org/wiki/Austrian_Federal_Railways) | [`oebb-hafas`](https://github.com/juliuste/oebb-hafas) | [docs](p/oebb/readme.md) | [example code](p/oebb/example.js) | [src](p/oebb/index.js)