Skip to content

Commit

Permalink
add STV profile βœ…πŸ“
Browse files Browse the repository at this point in the history
part of #207
  • Loading branch information
derhuerst committed Aug 5, 2021
1 parent f20466c commit 0ae13b0
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 0 deletions.
1 change: 1 addition & 0 deletions p/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ HAFAS endpoint | wrapper library | docs | example code | profile name
[Aachener Verkehrsverbund (AVV)](https://de.wikipedia.org/wiki/Verkehrsgemeinschaft_OsnabrΓΌck) | - | [docs](avv/readme.md) | [example](avv/example.js) | [`avv`](avv)
[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)
[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)
[*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)
Expand Down
15 changes: 15 additions & 0 deletions p/stv/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"auth": {
"type": "AID",
"aid": "wf7mcf9bv3nv8g5f"
},
"client": {
"type": "WEB",
"id": "VAO",
"name": "webapp"
},
"endpoint": "https://verkehrsauskunft.verbundlinie.at/bin/mgate.exe",
"ext": "VAO.13",
"ver": "1.32",
"defaultLanguage": "de"
}
49 changes: 49 additions & 0 deletions p/stv/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict'

const createClient = require('../..')
const stvProfile = require('.')

const client = createClient(stvProfile, 'hafas-client example')

const grazSonnenhang = '460413500'
const grazHΓΆdlweg = '460415400'

// client.journeys(grazSonnenhang, grazHΓΆdlweg, {
// 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(grazSonnenhang, {duration: 1})
// client.arrivals(grazSonnenhang, {duration: 10, linesOfStops: true})

client.locations('sonnenhang', {results: 3})
// client.stop(grazSonnenhang, {linesOfStops: true})
// client.nearby({
// type: 'location',
// id: '980027564',
// address: 'Eisengasse 10, 8020 Graz',
// latitude: 47.076553,
// longitude: 15.406064,
// }, {distance: 1000})
// client.reachableFrom({
// type: 'location',
// id: '980027564',
// address: 'Eisengasse 10, 8020 Graz',
// latitude: 47.076553,
// longitude: 15.406064,
// }, {
// maxDuration: 30,
// })

.then((data) => {
console.log(require('util').inspect(data, {depth: null, colors: true}))
})
.catch(console.error)
91 changes: 91 additions & 0 deletions p/stv/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'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 stvProfile = {
...baseProfile,
locale: 'at-DE',
timezone: 'Europe/Vienna',

products,

departuresGetPasslist: false,
departuresStbFltrEquiv: false,
refreshJourneyUseOutReconL: true,
trip: true,
reachableFrom: true,
}

module.exports = stvProfile
15 changes: 15 additions & 0 deletions p/stv/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# STV profile for `hafas-client`

[*Steirischer Verkehrsverbund (STV)*](https://de.wikipedia.org/wiki/Steirischer_Verkehrsverbund) is the local transport provider of [Styria](https://en.wikipedia.org/wiki/Styria) that runs its apps under the [*VerbundLinie*](https://www.verbundlinie.at) brand. This profile adds *STV*/*VerbundLinie* support to `hafas-client`.

## Usage

```js
const createClient = require('hafas-client')
const stvProfile = require('hafas-client/p/stv')

// create a client with STV profile
const client = createClient(stvProfile, 'my-awesome-program')
```

Check out the [code examples](example.js).
1 change: 1 addition & 0 deletions test/e2e/fixtures/9f33037cf954e62ae7ee72fbc9fbb8c4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ver":"1.32","ext":"VAO.13","lang":"deu","id":"urk4mgmgm6agg2wx","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":"421","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"prod_bus","txtS":"53","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"prod_regbus","txtS":"862","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"prod_regbus","txtS":"265","fg":{"r":255,"g":255,"b":255},"bg":{"r":0,"g":121,"b":58},"zIdx":1000},{"res":"ADR"}]},"match":{"field":"S","state":"L","locL":[{"lid":"A=1@O=Graz Sonnenhang@X=15481555@Y=47067034@U=81@L=460413500@B=1@p=1628121247@","type":"S","name":"Graz Sonnenhang","nameFormatted":{"text":"Graz Sonnenhang"},"icoX":0,"extId":"460413500","state":"F","crd":{"x":15481555,"y":47067034,"floor":0},"meta":true,"pCls":192,"wt":191,"isMainMast":true,"gidL":["at:46:4135"]},{"lid":"A=1@O=Stattegg Sonnenhang@X=15418613@Y=47141626@U=81@L=460362700@B=1@p=1628121247@","type":"S","name":"Stattegg Sonnenhang","nameFormatted":{"text":"Stattegg Sonnenhang"},"icoX":1,"extId":"460362700","state":"F","crd":{"x":15418613,"y":47141626,"floor":0},"meta":true,"pCls":128,"wt":188,"isMainMast":true,"gidL":["at:46:3627"]},{"lid":"A=1@O=Mehrnbach Sonnenhang@X=13443674@Y=48207189@U=81@L=444079800@B=1@p=1628121247@","type":"S","name":"Mehrnbach Sonnenhang","nameFormatted":{"text":"Mehrnbach Sonnenhang"},"icoX":2,"extId":"444079800","state":"F","crd":{"x":13443674,"y":48207189,"floor":0},"meta":true,"pCls":64,"wt":10,"isMainMast":true,"gidL":["at:44:40798"]},{"lid":"A=1@O=Waxenberg Sonnenhang@X=14191927@Y=48481945@U=81@L=444569400@B=1@p=1628121247@","type":"S","name":"Waxenberg Sonnenhang","nameFormatted":{"text":"Waxenberg Sonnenhang"},"icoX":3,"extId":"444569400","state":"F","crd":{"x":14191927,"y":48481945,"floor":0},"meta":true,"pCls":64,"wt":2,"isMainMast":true,"gidL":["at:44:45694"]},{"lid":"A=2@O=Sonnenhang, 3262 Wang@X=15020723@Y=48049231@U=103@b=980111207@B=1@p=1626331592@","type":"A","name":"Sonnenhang, 3262 Wang","nameFormatted":{"text":"Sonnenhang, 3262 Wang","textInstructionIntervalL":[{"startIndex":0,"endIndex":10,"textInstructionX":0},{"startIndex":10,"endIndex":21,"textInstructionX":1}]},"icoX":4,"state":"F","crd":{"x":15020723,"y":48049231}}]}}}]}
35 changes: 35 additions & 0 deletions test/e2e/fixtures/9f33037cf954e62ae7ee72fbc9fbb8c4.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"statusCode": 200,
"headers": {
"date": "Thu, 05 Aug 2021 18:10:17 GMT",
"server": "Apache",
"content-length": "841",
"content-type": "application/json; charset=utf-8",
"connection": "close"
},
"url": "https://verkehrsauskunft.verbundlinie.at/bin/mgate.exe",
"time": 266,
"request": {
"method": "POST",
"headers": {
"Content-Type": [
"application/json"
],
"Accept-Encoding": [
"gzip, br, deflate"
],
"Accept": [
"application/json"
],
"user-agent": [
"public-transc9279a930e0bport/hafas-client:test"
],
"Content-Length": [
"278"
],
"Connection": [
"close"
]
}
}
}
35 changes: 35 additions & 0 deletions test/e2e/stv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

const tap = require('tap')

const {createWhen} = require('./lib/util')
const createClient = require('../..')
const stvProfile = require('../../p/stv')
const createValidate = require('./lib/validate-fptf-with')

const when = createWhen(stvProfile.timezone, stvProfile.locale)
const cfg = {
when,
stationCoordsOptional: false,
products: stvProfile.products,
maxLatitude: 47.9504,
maxLongitude: 18.347,
minLatitude: 46.127,
minLongitude: 7.8635,
}
const validate = createValidate(cfg)

const client = createClient(stvProfile, 'public-transport/hafas-client:test')

const grazSonnenhang = '460413500'

tap.test('locations named "sonnenhang"', async (t) => {
const locations = await client.locations('sonnenhang')

validate(t, locations, 'locations', 'locations')
t.ok(locations.some((l) => {
return l.station && l.station.id === grazSonnenhang || l.id === grazSonnenhang
}), 'Graz Sonnenhang not found')

t.end()
})
1 change: 1 addition & 0 deletions tools/pull-profile-base-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ node -p "$query" "$src/de/vos-hafas-mgate.json" >../p/vos/base.json
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/stv-hafas-mgate.json" >../p/stv/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
Expand Down

0 comments on commit 0ae13b0

Please sign in to comment.