diff --git a/p/db-smartrbl/base.json b/p/db-smartrbl/base.json new file mode 100644 index 000000000..98dc9c6ff --- /dev/null +++ b/p/db-smartrbl/base.json @@ -0,0 +1,15 @@ +{ + "auth": { + "type": "AID", + "aid": "izfpmpj8tnh6acye" + }, + "client": { + "type": "WEB", + "id": "HAFAS", + "v": "1.0.0", + "name": "Test-Client" + }, + "endpoint": "https://db-smartrbl.hafas.de/mct/mgate", + "ver": "1.60", + "defaultLanguage": "de" +} diff --git a/p/db-smartrbl/example.js b/p/db-smartrbl/example.js new file mode 100644 index 000000000..f63f13f4c --- /dev/null +++ b/p/db-smartrbl/example.js @@ -0,0 +1,48 @@ +import {inspect} from 'util' +import {createClient} from '../../index.js' +import {profile as dbProfile} from './index.js' + +const client = createClient(dbProfile, 'eoqifjefoijf') + +const berlinOstbahnhof = '8010255' +const freiburgHbf = '8000107' + +// let data = await client.locations('freiburg') + +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.stop(berlinOstbahnhof) +// 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-smartrbl/index.js b/p/db-smartrbl/index.js new file mode 100644 index 000000000..2bb9385ef --- /dev/null +++ b/p/db-smartrbl/index.js @@ -0,0 +1,108 @@ +// 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: confirm that these are 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, + + trip: true, + refreshJourneyUseOutReconL: true, + reachableFrom: true, + radar: true, +} + +export { + profile, +} diff --git a/p/db-smartrbl/readme.md b/p/db-smartrbl/readme.md new file mode 100644 index 000000000..7c6f796c3 --- /dev/null +++ b/p/db-smartrbl/readme.md @@ -0,0 +1,13 @@ +# Deutsche Bahn "smartrbl" profile for `hafas-client` + +## Usage + +```js +import {createClient} from 'hafas-client' +import {profile as dbSmartrblProfile} from 'hafas-client/p/db-smartrbl/index.js' + +const userAgent = 'link-to-your-project-or-email' // adapt this to your project! + +// create a client with the Deutsche Bahn "smartrbl" profile +const client = createClient(dbSmartrblProfile, userAgent) +``` diff --git a/p/readme.md b/p/readme.md index 088dc0220..1456907e8 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 "smartrbl" | – | [docs](db-smartrbl/readme.md) | [example](db-smartrbl/example.js) | [`db-smartrbl`](db-smartrbl) ## writing your own diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index 5d17ece8b..9f97340f2 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -49,6 +49,7 @@ node -p "$query" "$src/de/rmv-hafas-mgate.json" >../p/rmv/base.json node -p "$query" "$src/de/rsag-hafas-mgate.json" >../p/rsag/base.json node -p "$query" "$src/de/saarvv-hafas-mgate.json" >../p/saarfahrplan/base.json node -p "$query" "$src/de/db-sbahn-muenchen-hafas-mgate.json" >../p/sbahn-muenchen/base.json +node -p "$query" "$src/de/db-smartrbl-hafas-mgate.json" >../p/db-smartrbl/base.json node -p "$query" "$src/be/nmbs-sncb-hafas-mgate.json" >../p/sncb/base.json node -p "$query" "$src/at/svv-hafas-mgate.json" >../p/svv/base.json node -p "$query" "$src/de/vbb-hafas-mgate.json" >../p/vbb/base.json