add PKP profile

This commit is contained in:
Julius Tens 2020-03-11 20:00:54 +01:00 committed by Jannis Redmann
parent 299b5ac8ae
commit d5116c2399
5 changed files with 129 additions and 0 deletions

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

@ -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)

28
p/pkp/index.js Normal file
View file

@ -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

36
p/pkp/products.js Normal file
View file

@ -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
}
]

18
p/pkp/readme.md Normal file
View file

@ -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*)

View file

@ -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)