diff --git a/p/readme.md b/p/readme.md index b71a7099..58ee47a8 100644 --- a/p/readme.md +++ b/p/readme.md @@ -40,8 +40,9 @@ HAFAS endpoint | wrapper library | docs | example code | profile name [Rejseplanen in Denmark](http://www.rejseplanen.dk) | - | [docs](rejseplanen/readme.md) | [example](rejseplanen/example.js) | [`rejseplanen`](rejseplanen) [Innsbrucker Verkehrsbetriebe (IVB)](https://de.wikipedia.org/wiki/Innsbrucker_Verkehrsbetriebe_und_Stubaitalbahn) | - | [docs](ivb/readme.md) | [example](ivb/example.js) | [`ivb`](ivb) [Oberösterreichischer Verkehrsverbund (OÖVV)](https://de.wikipedia.org/wiki/Oberösterreichischer_Verkehrsverbund) | - | [docs](ooevv/readme.md) | [example](ooevv/example.js) | [`ooevv`](ooevv) +[Salzburg](https://en.wikipedia.org/wiki/Salzburg) | - | [docs](salzburg/readme.md) | [example](salzburg/example.js) | [`salzburg`](salzburg) [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) +[Salzburger Verkehrsverbund (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) diff --git a/p/salzburg/base.json b/p/salzburg/base.json new file mode 100644 index 00000000..2916a511 --- /dev/null +++ b/p/salzburg/base.json @@ -0,0 +1,13 @@ +{ + "auth": { + "type": "AID", + "aid": "wf7mcf9bv3nv8g5f" + }, + "client": { + "type": "WEB", + "id": "VAO", + "name": "webapp" + }, + "endpoint": "https://verkehrsauskunft.salzburg.gv.at/bin/mgate.exe", + "defaultLanguage": "de" +} diff --git a/p/salzburg/example.js b/p/salzburg/example.js new file mode 100644 index 00000000..6c43d0f0 --- /dev/null +++ b/p/salzburg/example.js @@ -0,0 +1,49 @@ +'use strict' + +const createClient = require('../..') +const salzburgProfile = require('.') + +const client = createClient(salzburgProfile, 'hafas-client example') + +const salzburgGaswerkgasse = '455001300' +const oberndorfKrankenhaus = '455110200' + +// client.journeys(salzburgGaswerkgasse, oberndorfKrankenhaus, { +// 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[0] +// return client.trip(leg.tripId, leg.line.name, {polyline: true}) +// }) + +// client.departures(salzburgGaswerkgasse, {duration: 1}) +// client.arrivals(salzburgGaswerkgasse, {duration: 10, linesOfStops: true}) + +client.locations('krankenhaus', {results: 3}) +// client.stop(salzburgGaswerkgasse, {linesOfStops: true}) +// client.nearby({ +// type: 'location', +// id: '980100611', +// address: 'Rupertgasse 5, 5020 Salzburg', +// latitude: 47.806891, +// longitude: 13.050503, +// }, {distance: 1000}) +// client.reachableFrom({ +// type: 'location', +// id: '980100611', +// address: 'Rupertgasse 5, 5020 Salzburg', +// latitude: 47.806891, +// longitude: 13.050503, +// }, { +// maxDuration: 30, +// }) + +.then((data) => { + console.log(require('util').inspect(data, {depth: null, colors: true})) +}) +.catch(console.error) diff --git a/p/salzburg/index.js b/p/salzburg/index.js new file mode 100644 index 00000000..08fa282b --- /dev/null +++ b/p/salzburg/index.js @@ -0,0 +1,93 @@ +'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 salzburgProfile = { + ...baseProfile, + ver: '1.32', + + locale: 'at-DE', + timezone: 'Europe/Vienna', + + products, + + departuresGetPasslist: false, + departuresStbFltrEquiv: false, + refreshJourneyUseOutReconL: true, + trip: true, + reachableFrom: true, +} + +module.exports = salzburgProfile diff --git a/p/salzburg/readme.md b/p/salzburg/readme.md new file mode 100644 index 00000000..364d2852 --- /dev/null +++ b/p/salzburg/readme.md @@ -0,0 +1,15 @@ +# Salzburg profile for `hafas-client` + +The government of [Salzburg](https://en.wikipedia.org/wiki/Salzburg) operates a [public transport planner](https://verkehrsauskunft.salzburg.gv.at). This profile adds support for it to `hafas-client`. + +## Usage + +```js +const createClient = require('hafas-client') +const salzburgProfile = require('hafas-client/p/salzburg') + +// create a client with Salzburg profile +const client = createClient(salzburgProfile, 'my-awesome-program') +``` + +Check out the [code examples](example.js). diff --git a/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015 b/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015 new file mode 100644 index 00000000..9951cd97 --- /dev/null +++ b/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015 @@ -0,0 +1 @@ +{"ver":"1.32","lang":"deu","id":"f24w6gmxk6qkhg8g","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":{"txtInstL":[{"id":"street","type":"NONE","mode":"ADD"},{"id":"city","type":"NONE","mode":"ADD"}],"icoL":[{"res":"prod_regbus","txtS":"120","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"ADR"},{"res":"prod_bus","txtS":"1","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000}]},"match":{"field":"S","state":"L","locL":[{"lid":"A=1@O=Salzburg Gaswerkgasse@X=13033118@Y=47811242@U=81@L=455001300@B=1@p=1628121247@","type":"S","name":"Salzburg Gaswerkgasse","nameFormatted":{"text":"Salzburg Gaswerkgasse"},"icoX":0,"extId":"455001300","state":"F","crd":{"x":13033118,"y":47811242,"floor":0},"meta":true,"pCls":192,"wt":219,"isMainMast":true,"gidL":["at:45:50013"]},{"lid":"A=2@O=Gaswerkgasse, 4400 Steyr@X=14416468@Y=48042840@U=103@b=980038961@B=1@p=1626331592@","type":"A","name":"Gaswerkgasse, 4400 Steyr","nameFormatted":{"text":"Gaswerkgasse, 4400 Steyr","textInstructionIntervalL":[{"startIndex":0,"endIndex":12,"textInstructionX":0},{"startIndex":12,"endIndex":24,"textInstructionX":1}]},"icoX":1,"state":"F","crd":{"x":14416468,"y":48042840}},{"lid":"A=2@O=Gaswerkgasse, 4810 Gmunden@X=13807072@Y=47915112@U=103@b=980038962@B=1@p=1626331592@","type":"A","name":"Gaswerkgasse, 4810 Gmunden","nameFormatted":{"text":"Gaswerkgasse, 4810 Gmunden","textInstructionIntervalL":[{"startIndex":0,"endIndex":12,"textInstructionX":0},{"startIndex":12,"endIndex":26,"textInstructionX":1}]},"icoX":1,"state":"F","crd":{"x":13807072,"y":47915112}},{"lid":"A=2@O=Gaswerkgasse, 5020 Salzburg@X=13033010@Y=47808572@U=103@b=980038963@B=1@p=1626331592@","type":"A","name":"Gaswerkgasse, 5020 Salzburg","nameFormatted":{"text":"Gaswerkgasse, 5020 Salzburg","textInstructionIntervalL":[{"startIndex":0,"endIndex":12,"textInstructionX":0},{"startIndex":12,"endIndex":27,"textInstructionX":1}]},"icoX":1,"state":"F","crd":{"x":13033010,"y":47808572}},{"lid":"A=1@O=Krems an der Donau Gaswerkgasse@X=15590918@Y=48410013@U=81@L=432066900@B=1@p=1628121247@","type":"S","name":"Krems an der Donau Gaswerkgasse","nameFormatted":{"text":"Krems an der Donau Gaswerkgasse"},"icoX":2,"extId":"432066900","state":"F","crd":{"x":15590918,"y":48410013,"floor":0},"meta":true,"pCls":128,"wt":9,"isMainMast":true,"gidL":["at:43:20669"]}]}}}]} \ No newline at end of file diff --git a/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015.headers b/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015.headers new file mode 100644 index 00000000..88729867 --- /dev/null +++ b/test/e2e/fixtures/467a5ea1576cfb41e857daca932e6015.headers @@ -0,0 +1,35 @@ +{ + "statusCode": 200, + "headers": { + "date": "Thu, 05 Aug 2021 18:10:53 GMT", + "server": "Apache", + "content-length": "817", + "content-type": "application/json; charset=utf-8", + "connection": "close" + }, + "url": "https://verkehrsauskunft.salzburg.gv.at/bin/mgate.exe", + "time": 335, + "request": { + "method": "POST", + "headers": { + "Content-Type": [ + "application/json" + ], + "Accept-Encoding": [ + "gzip, br, deflate" + ], + "Accept": [ + "application/json" + ], + "user-agent": [ + "publibc8d54e81822c-transport/hafas-client:test" + ], + "Content-Length": [ + "265" + ], + "Connection": [ + "close" + ] + } + } +} \ No newline at end of file diff --git a/test/e2e/salzburg.js b/test/e2e/salzburg.js new file mode 100644 index 00000000..1e90546b --- /dev/null +++ b/test/e2e/salzburg.js @@ -0,0 +1,35 @@ +'use strict' + +const tap = require('tap') + +const {createWhen} = require('./lib/util') +const createClient = require('../..') +const salzburgProfile = require('../../p/salzburg') +const createValidate = require('./lib/validate-fptf-with') + +const when = createWhen(salzburgProfile.timezone, salzburgProfile.locale) +const cfg = { + when, + stationCoordsOptional: false, + products: salzburgProfile.products, + maxLatitude: 47.9504, + maxLongitude: 17.0892, + minLatitude: 45.7206, + minLongitude: 7.8635, +} +const validate = createValidate(cfg) + +const client = createClient(salzburgProfile, 'public-transport/hafas-client:test') + +const salzburgGaswerkgasse = '455001300' + +tap.test('locations named "gaswerkgasse"', async (t) => { + const locations = await client.locations('gaswerkgasse') + + validate(t, locations, 'locations', 'locations') + t.ok(locations.some((l) => { + return l.station && l.station.id === salzburgGaswerkgasse || l.id === salzburgGaswerkgasse + }), 'Salzburg Gaswerkgasse not found') + + t.end() +}) diff --git a/tools/pull-profile-base-data.sh b/tools/pull-profile-base-data.sh index e4d019d2..be4503dc 100755 --- a/tools/pull-profile-base-data.sh +++ b/tools/pull-profile-base-data.sh @@ -62,6 +62,7 @@ node -p "$query" "$src/de/vrn-hafas-mgate.json" >../p/vrn/base.json 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/salzburg-hafas-mgate.json" >../p/salzburg/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