From db2cbfdc4580b96d376dfb45c7d78d919a04a8ef Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 5 Aug 2021 19:56:05 +0200 Subject: [PATCH] =?UTF-8?q?add=20VOR=20profile=20=E2=9C=85=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit part of #207 --- p/readme.md | 1 + p/vor/base.json | 14 +++ p/vor/example.js | 49 +++++++++ p/vor/index.js | 100 ++++++++++++++++++ p/vor/readme.md | 15 +++ .../fixtures/f6207a713f003e9e6278d1a8085dc264 | 1 + .../f6207a713f003e9e6278d1a8085dc264.headers | 35 ++++++ test/e2e/vor.js | 35 ++++++ tools/pull-profile-base-data.sh | 1 + 9 files changed, 251 insertions(+) create mode 100644 p/vor/base.json create mode 100644 p/vor/example.js create mode 100644 p/vor/index.js create mode 100644 p/vor/readme.md create mode 100644 test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264 create mode 100644 test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264.headers create mode 100644 test/e2e/vor.js diff --git a/p/readme.md b/p/readme.md index 95b754ea..b71a7099 100644 --- a/p/readme.md +++ b/p/readme.md @@ -43,6 +43,7 @@ HAFAS endpoint | wrapper library | docs | example code | profile name [Steirischer Verkehrsverbund (STV)](https://de.wikipedia.org/wiki/Steirischer_Verkehrsverbund) | - | [docs](stv/readme.md) | [example](stv/example.js) | [`stv`](stv) [Salzburg public transport (SVV)](https://de.wikipedia.org/wiki/Salzburger_Verkehrsverbund) | - | [docs](svv/readme.md) | [example](svv/example.js) | [`svv`](svv) [Verkehrsverbund Tirol (VVT)](https://de.wikipedia.org/wiki/Verkehrsverbund_Tirol) | - | [docs](vvt/readme.md) | [example](vvt/example.js) | [`vvt`](vvt) +[Verkehrsverbund Ost-Region (VOR)](https://de.wikipedia.org/wiki/Verkehrsverbund_Ost-Region) | - | [docs](vor/readme.md) | [example](vor/example.js) | [`vor`](vor) [*Kärntner Linien/Verkehrsverbund Kärnten (VKG/VVK)*](https://de.wikipedia.org/wiki/Verkehrsverbund_Kärnten) | - | [docs](vkg/readme.md) | [example](vkg/example.js) | [`vkg`](vkg) [Verkehrsverbund Vorarlberg (VVV)](https://de.wikipedia.org/wiki/Verkehrsverbund_Vorarlberg) | - | [docs](vvv/readme.md) | [example](vvv/example.js) | [`vvv`](vvv) [*Transports publics genevois (TPG)*](https://en.wikipedia.org/wiki/Geneva_Public_Transport) (Geneva) | - | [docs](tpg/readme.md) | [example](tpg/example.js) | [`tpg`](tpg) diff --git a/p/vor/base.json b/p/vor/base.json new file mode 100644 index 00000000..e001afd6 --- /dev/null +++ b/p/vor/base.json @@ -0,0 +1,14 @@ +{ + "auth": { + "type": "AID", + "aid": "and20201hf7mcf9bv3nv8g5f" + }, + "client": { + "type": "AND", + "id": "VAO" + }, + "endpoint": "https://anachb.vor.at/bin/mgate.exe", + "ext": "VAO.11", + "ver": "1.27", + "defaultLanguage": "de" +} diff --git a/p/vor/example.js b/p/vor/example.js new file mode 100644 index 00000000..726c84cd --- /dev/null +++ b/p/vor/example.js @@ -0,0 +1,49 @@ +'use strict' + +const createClient = require('../..') +const vorProfile = require('.') + +const client = createClient(vorProfile, 'hafas-client example') + +const stPöltenLinzerTor = '431277900' +const eisenstadtSchlossplatz = '415003300' + +// client.journeys(stPöltenLinzerTor, eisenstadtSchlossplatz, { +// results: 1, stopovers: true, +// }) +// .then(({journeys}) => { +// const [journey] = journeys +// return client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) +// }) +// .then(({journeys}) => { +// const [journey] = journeys +// const leg = journey.legs.find(l => !!l.line) +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) + +// client.departures(stPöltenLinzerTor, {duration: 20}) +// client.arrivals(stPöltenLinzerTor, {duration: 10, linesOfStops: true}) + +client.locations('schlossplatz', {results: 3}) +// client.stop(stPöltenLinzerTor, {linesOfStops: true}) +// client.nearby({ +// type: 'location', +// id: '980021284', +// address: 'Christalniggasse 6, 2500 Baden', +// latitude: 48.005516, +// longitude: 16.241404, +// }, {distance: 1000}) +// client.reachableFrom({ +// type: 'location', +// id: '980021284', +// address: 'Christalniggasse 6, 2500 Baden', +// latitude: 48.005516, +// longitude: 16.241404, +// }, { +// maxDuration: 30, +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/vor/index.js b/p/vor/index.js new file mode 100644 index 00000000..5f8c7880 --- /dev/null +++ b/p/vor/index.js @@ -0,0 +1,100 @@ +'use strict' + +const baseProfile = require('./base.json') + +const products = [{ + id: 'train-and-s-bahn', + mode: 'train', + bitmasks: [1, 2], + name: 'Bahn & S-Bahn', + short: 'Bahn & S-Bahn', + default: true, +}, { + id: 'u-bahn', + mode: 'train', + bitmasks: [4], + name: 'U-Bahn', + short: 'U-Bahn', + default: true, +}, { + id: 'tram', + mode: 'train', + bitmasks: [16], + name: 'Straßenbahn', + short: 'Straßenbahn', + default: true, +}, { + id: 'city-bus', + mode: 'bus', + bitmasks: [128], + name: 'Stadtbus', + short: 'Stadtbus', + default: true, +}, { + id: 'regional-bus', + mode: 'bus', + bitmasks: [64], + name: 'Regionalbus', + short: 'Regionalbus', + default: true, +}, { + id: 'long-distance-bus', + mode: 'bus', + bitmasks: [32], + name: 'Fernbus', + short: 'Fernbus', + default: true, +}, { + id: 'other-bus', + mode: 'bus', + bitmasks: [2048], + name: 'sonstige Busse', + short: 'sonstige Busse', + default: true, +}, { + id: 'aerial-lift', + mode: 'gondola', + bitmasks: [256], + name: 'Seil-/Zahnradbahn', + short: 'Seil-/Zahnradbahn', + default: true, +}, { + id: 'ferry', + mode: 'watercraft', + bitmasks: [512], + name: 'Schiff', + short: 'Schiff', + default: true, +}, { + id: 'on-call', + mode: 'taxi', + bitmasks: [1024], + name: 'Anrufsammeltaxi', + short: 'AST', + default: true, +}] + +const vorProfile = { + ...baseProfile, + auth: { + type: 'USER', + aid: 'and20201hf7mcf9bv3nv8g5f', + user: 'mobile', + pw: '87a6f8ZbnBih32', + }, + addMicMac: true, + salt: '6633673735743766726667323938336A', + + locale: 'at-DE', + timezone: 'Europe/Vienna', + + products, + + departuresGetPasslist: false, + departuresStbFltrEquiv: false, + refreshJourneyUseOutReconL: true, + trip: true, + reachableFrom: true, +} + +module.exports = vorProfile diff --git a/p/vor/readme.md b/p/vor/readme.md new file mode 100644 index 00000000..1387f43f --- /dev/null +++ b/p/vor/readme.md @@ -0,0 +1,15 @@ +# VOR profile for `hafas-client` + +[*Verkehrsverbund Ost-Region (VOR)*](https://de.wikipedia.org/wiki/Verkehrsverbund_Ost-Region) is the local transport provider of [Vienna](https://en.wikipedia.org/wiki/Vienna), [Lower Austria](https://en.wikipedia.org/wiki/Lower_Austria) and [Burgenland](https://en.wikipedia.org/wiki/Burgenland); It runs its apps under the [*AnachB*](https://anachb.vor.at) brand. This profile adds *VOR*/*AnachB* support to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const vorProfile = require('hafas-client/p/vor') + +// create a client with VOR profile +const client = createClient(vorProfile, 'my-awesome-program') +``` + +Check out the [code examples](example.js). diff --git a/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264 b/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264 new file mode 100644 index 00000000..bc77f248 --- /dev/null +++ b/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264 @@ -0,0 +1 @@ +{"ver":"1.27","ext":"VAO.11","lang":"deu","id":"ae4g4gmxm2as8i8g","err":"OK","cInfo":{"code":"OK","url":"","msg":""},"graph":{"id":"standard","index":0},"subGraph":{"id":"global","index":0},"view":{"id":"standard","index":0,"type":"WGS84"},"svcResL":[{"meth":"LocMatch","err":"OK","res":{"common":{"remL":[{"type":"W","code":"WW","txtN":"WEBVIEW","url":"https://app.verkehrsauskunft.at/bin/query.exe/dn?tpl=webview_poi&performLocating=128&look_station=960073768&look_nv=get_infotext|yes|get_attributes|yes&look_stationpool=130"}],"txtInstL":[{"id":"street","type":"NONE","mode":"ADD"},{"id":"city","type":"NONE","mode":"ADD"}],"icoL":[{"res":"prod_ic_bus","txtS":"485","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"ADR"},{"res":"PCAT_SEHENWUERDIGKEIT","zIdx":900},{"res":"prod_ic_bus","txtS":"715","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"prod_mh"}]},"match":{"field":"S","state":"L","locL":[{"lid":"A=1@O=St. Pölten Linzer Tor@X=15621203@Y=48202371@U=81@L=431277900@B=1@p=1628121247@","type":"S","name":"St. Pölten Linzer Tor","nameFormatted":{"text":"St. Pölten Linzer Tor"},"icoX":0,"extId":"431277900","state":"F","crd":{"x":15621203,"y":48202371,"floor":0},"meta":true,"pCls":192,"wt":219,"isMainMast":true,"gidL":["at:43:12779"]},{"lid":"A=2@O=Linzer Tor, 4780 Schärding@X=13432536@Y=48456343@U=103@b=980074931@B=1@p=1626331592@","type":"A","name":"Linzer Tor, 4780 Schärding","nameFormatted":{"text":"Linzer Tor, 4780 Schärding","textInstructionIntervalL":[{"startIndex":0,"endIndex":10,"textInstructionX":0},{"startIndex":10,"endIndex":26,"textInstructionX":1}]},"icoX":1,"state":"F","crd":{"x":13432536,"y":48456343}},{"lid":"A=4@O=Linzer Tor, 4780 Schärding (Sehenswürdigkeit)@X=13432626@Y=48456298@U=130@L=960073768@B=1@p=1628123037@","type":"P","name":"Linzer Tor, 4780 Schärding (Sehenswürdigkeit)","nameFormatted":{"text":"Linzer Tor, 4780 Schärding (Sehenswürdigkeit)","textInstructionIntervalL":[{"startIndex":10,"endIndex":45,"textInstructionX":1}]},"icoX":2,"extId":"960073768","state":"F","crd":{"x":13432626,"y":48456298,"floor":0},"mcpData":{"type":"P","occupancy":"N","mcpid":"0","externalId":"oeamtc_tf-608658700"},"msgL":[{"type":"REM","remX":0,"sty":"I","dspl":"U","tagL":["RES_LOC_WEB","RES_LOC_FLY_WEB"],"sort":684195840}]},{"lid":"A=1@O=Stein an der Donau Linzer Tor/DPU@X=15576319@Y=48399981@U=81@L=431176300@B=1@p=1628121247@","type":"S","name":"Stein an der Donau Linzer Tor/DPU","nameFormatted":{"text":"Stein an der Donau Linzer Tor/DPU"},"icoX":3,"extId":"431176300","state":"F","crd":{"x":15576319,"y":48399981,"floor":0},"meta":true,"pCls":192,"wt":39,"isMainMast":true,"gidL":["at:43:11763"]},{"lid":"A=1@O=LINZERÖDT@X=14518640@Y=48077700@U=81@L=900002269@B=1@p=1628121247@","type":"S","name":"LINZERÖDT","nameFormatted":{"text":"LINZERÖDT"},"icoX":4,"extId":"900002269","state":"F","crd":{"x":14518640,"y":48077700,"floor":0},"meta":true,"pCls":64,"wt":10}]}}}]} \ No newline at end of file diff --git a/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264.headers b/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264.headers new file mode 100644 index 00000000..10087738 --- /dev/null +++ b/test/e2e/fixtures/f6207a713f003e9e6278d1a8085dc264.headers @@ -0,0 +1,35 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 05 Aug 2021 18:10:37 GMT", + "server": "Apache", + "content-length": "1176", + "content-type": "application/json; charset=utf-8", + "connection": "close" + }, + "url": "https://anachb.vor.at/bin/mgate.exe?mic=edda4ed2f647b0775e1bdb42ecc1be52&mac=3e9f423493a839202d16f9f484b06663", + "time": 273, + "request": { + "method": "POST", + "headers": { + "Content-Type": [ + "application/json" + ], + "Accept-Encoding": [ + "gzip, br, deflate" + ], + "Accept": [ + "application/json" + ], + "user-agent": [ + "pu5b67db88d17fblic-transport/hafas-client:test" + ], + "Content-Length": [ + "309" + ], + "Connection": [ + "close" + ] + } + } +} \ No newline at end of file diff --git a/test/e2e/vor.js b/test/e2e/vor.js new file mode 100644 index 00000000..346f052a --- /dev/null +++ b/test/e2e/vor.js @@ -0,0 +1,35 @@ +'use strict' + +const tap = require('tap') + +const {createWhen} = require('./lib/util') +const createClient = require('../..') +const vorProfile = require('../../p/vor') +const createValidate = require('./lib/validate-fptf-with') + +const when = createWhen(vorProfile.timezone, vorProfile.locale) +const cfg = { + when, + stationCoordsOptional: false, + products: vorProfile.products, + maxLatitude: 47.9504, + maxLongitude: 17.0892, + minLatitude: 45.7206, + minLongitude: 7.8635, +} +const validate = createValidate(cfg) + +const client = createClient(vorProfile, 'public-transport/hafas-client:test') + +const stPöltenLinzerTor = '431277900' + +tap.test('locations named "linzer tor"', async (t) => { + const locations = await client.locations('linzer tor') + + validate(t, locations, 'locations', 'locations') + t.ok(locations.some((l) => { + return l.station && l.station.id === stPöltenLinzerTor || l.id === stPöltenLinzerTor + }), 'St. Pölten Linzer Tor not found') + + t.end() +}) diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index d4646608..e4d019d2 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -63,6 +63,7 @@ node -p "$query" "$src/de/vsn-hafas-mgate.json" >../p/vsn/base.json node -p "$query" "$src/at/ivb-hafas-mgate.json" >../p/ivb/base.json node -p "$query" "$src/at/ooevv-hafas-mgate.json" >../p/ooevv/base.json node -p "$query" "$src/at/stv-hafas-mgate.json" >../p/stv/base.json +node -p "$query" "$src/at/vor-hafas-mgate.json" >../p/vor/base.json node -p "$query" "$src/at/vvt-hafas-mgate.json" >../p/vvt/base.json node -p "$query" "$src/at/vvv-hafas-mgate.json" >../p/vvv/base.json node -p "$query" "$src/ch/bls-hafas-mgate.json" >../p/bls/base.json