From 0e34e5001f15603b5f6415d3242cdd4c060684f9 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 25 Apr 2023 14:06:54 +0200 Subject: [PATCH] =?UTF-8?q?add=20DB=20Streckenagent=20profile=20?= =?UTF-8?q?=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p/db-streckenagent/base.json | 17 +++++ p/db-streckenagent/example.js | 50 +++++++++++++++ p/db-streckenagent/index.js | 109 ++++++++++++++++++++++++++++++++ p/db-streckenagent/readme.md | 15 +++++ p/readme.md | 1 + tools/pull-profile-base-data.sh | 1 + 6 files changed, 193 insertions(+) create mode 100644 p/db-streckenagent/base.json create mode 100644 p/db-streckenagent/example.js create mode 100644 p/db-streckenagent/index.js create mode 100644 p/db-streckenagent/readme.md diff --git a/p/db-streckenagent/base.json b/p/db-streckenagent/base.json new file mode 100644 index 000000000..2c088a8f7 --- /dev/null +++ b/p/db-streckenagent/base.json @@ -0,0 +1,17 @@ +{ + "auth": { + "type": "AID", + "aid": "Xd91BNAVkuI6rr6z" + }, + "salt": "7a374446424e41563048766836715137", + "client": { + "type": "IPH", + "id": "DB-REGIO-BNAV", + "v": "3000500", + "name": "StreckenagentPROD-APPSTORE" + }, + "endpoint": "https://bnav.hafas.de/bin/mgate.exe", + "ext": "DB.R19.12.a", + "ver": "1.18", + "defaultLanguage": "de" +} diff --git a/p/db-streckenagent/example.js b/p/db-streckenagent/example.js new file mode 100644 index 000000000..7ce12f2f5 --- /dev/null +++ b/p/db-streckenagent/example.js @@ -0,0 +1,50 @@ +import {inspect} from 'util' +import {createClient} from '../../index.js' +import {profile as dbRegioProfile} from './index.js' + +const client = createClient(dbRegioProfile, 'hafas-client-example') + +const berlinOstbahnhof = '8010255' +const freiburgHbf = '8000107' + +let data = await client.journeys(berlinOstbahnhof, freiburgHbf, {results: 1, tickets: true}) +// { +// const {journeys} = data +// const leg = journeys[0].legs[0] +// data = await client.trip(leg.tripId, {polyline: true}) +// } +// { +// const {journeys} = data +// const [journey] = journeys +// data = await client.refreshJourney(journey.refreshToken, { +// stopovers: true, +// remarks: true, +// }) +// } + +// let data = await client.departures(berlinOstbahnhof) +// let data = await client.arrivals(berlinOstbahnhof, {duration: 10, linesOfStops: true}) +// let data = await client.locations('südkreuz') +// let data = await client.stop(freiburgHbf) +// let data = await client.nearby({ +// type: 'location', +// latitude: 52.4751309, +// longitude: 13.3656537, +// }, {results: 1}) +// let data = await client.reachableFrom({ +// type: 'location', +// address: '13353 Berlin-Wedding, Torfstr. 17', +// latitude: 52.541797, +// longitude: 13.350042, +// }, { +// when: new Date('2023-08-27T10:00+02:00'), +// maxDuration: 50, +// }) +// let data = await client.radar({ +// north: 52.52411, +// west: 13.41002, +// south: 52.51942, +// east: 13.41709, +// }, {results: 10}) + +console.log(inspect(data, {depth: null, colors: true})) diff --git a/p/db-streckenagent/index.js b/p/db-streckenagent/index.js new file mode 100644 index 000000000..ef34f8529 --- /dev/null +++ b/p/db-streckenagent/index.js @@ -0,0 +1,109 @@ +// todo: use import assertions once they're supported by Node.js & ESLint +// https://github.com/tc39/proposal-import-assertions +import {createRequire} from 'module' +const require = createRequire(import.meta.url) + +const baseProfile = require('./base.json') + +const products = [ + // copied from the `db` profile + // todo: are these correct? + { + id: 'nationalExpress', + mode: 'train', + bitmasks: [1], + name: 'InterCityExpress', + short: 'ICE', + default: true, + }, + { + id: 'national', + mode: 'train', + bitmasks: [2], + name: 'InterCity & EuroCity', + short: 'IC/EC', + default: true, + }, + { + id: 'regionalExpress', + mode: 'train', + bitmasks: [4], + name: 'RegionalExpress & InterRegio', + short: 'RE/IR', + default: true, + }, + { + id: 'regional', + mode: 'train', + bitmasks: [8], + name: 'Regio', + short: 'RB', + default: true, + }, + { + id: 'suburban', + mode: 'train', + bitmasks: [16], + name: 'S-Bahn', + short: 'S', + default: true, + }, + { + id: 'bus', + mode: 'bus', + bitmasks: [32], + name: 'Bus', + short: 'B', + default: true, + }, + { + id: 'ferry', + mode: 'watercraft', + bitmasks: [64], + name: 'Ferry', + short: 'F', + default: true, + }, + { + id: 'subway', + mode: 'train', + bitmasks: [128], + name: 'U-Bahn', + short: 'U', + default: true, + }, + { + id: 'tram', + mode: 'train', + bitmasks: [256], + name: 'Tram', + short: 'T', + default: true, + }, + { + id: 'taxi', + mode: 'taxi', + bitmasks: [512], + name: 'Group Taxi', + short: 'Taxi', + default: true, + }, +] + +const profile = { + ...baseProfile, + locale: 'de-DE', + timezone: 'Europe/Berlin', + + products, + + // todo + // refreshJourneyUseOutReconL: true, + // trip: true, + // radar: true, + // reachableFrom: true, +} + +export { + profile, +} diff --git a/p/db-streckenagent/readme.md b/p/db-streckenagent/readme.md new file mode 100644 index 000000000..d9e6ac82a --- /dev/null +++ b/p/db-streckenagent/readme.md @@ -0,0 +1,15 @@ +# DB Streckenagent profile for `hafas-client` + +[*DB Regio*](https://en.wikipedia.org/wiki/DB_Regio) is a major prodiver of regional transport services in Germany. This profile adds support for [*Streckenagent*](https://www.bahn.de/service/mobile/streckenagent-app)'s backend to `hafas-client`. + +## Usage + +```js +import {createClient} from 'hafas-client' +import {profile as dbRegioProfile} from 'hafas-client/p/db-regio/index.js' + +const userAgent = 'link-to-your-project-or-email' // adapt this to your project! + +// create a client with DB Streckenagent profile +const client = createClient(dbRegioProfile, userAgent) +``` diff --git a/p/readme.md b/p/readme.md index 088dc0220..952d9bb8f 100644 --- a/p/readme.md +++ b/p/readme.md @@ -50,6 +50,7 @@ HAFAS endpoint | wrapper library | docs | example code | profile name [*Transports publics genevois (TPG)*](https://en.wikipedia.org/wiki/Geneva_Public_Transport) (Geneva) | - | [docs](tpg/readme.md) | [example](tpg/example.js) | [`tpg`](tpg) [*BLS AG*](https://en.wikipedia.org/wiki/BLS_AG) (Bern) | - | [docs](bls/readme.md) | [example](bls/example.js) | [`bls`](bls) [Zürich public transport (ZVV)](https://en.wikipedia.org/wiki/Zürcher_Verkehrsverbund) | - | [docs](zvv/readme.md) | [example](zvv/example.js) | [`zvv`](zvv) +[Deutsche Bahn *Streckenagent*](https://www.bahn.de/service/mobile/streckenagent-app) | – | [docs](db-streckenagent/readme.md) | [example](db-streckenagent/example.js) | [`db-streckenagent`](db-streckenagent) ## writing your own diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index 5d17ece8b..80b4b4791 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -34,6 +34,7 @@ node -p "$query" "$src/de/bvg-hafas-mgate.json" >../p/bvg/base.json node -p "$query" "$src/lu/cfl-hafas-mgate.json" >../p/cfl/base.json node -p "$query" "$src/us/cmta-hafas-mgate.json" >../p/cmta/base.json node -p "$query" "$src/de/db-hafas-mgate.json" >../p/db/base.json +node -p "$query" "$src/de/db-streckenagent-hafas-mgate.json" >../p/db-streckenagent/base.json node -p "$query" "$src/de/db-busradar-nrw-hafas-mgate.json" >../p/db-busradar-nrw/base.json node -p "$query" "$src/de/nasa-hafas-mgate.json" >../p/insa/base.json node -p "$query" "$src/de/invg-hafas-mgate.json" >../p/invg/base.json