db-vendo-client/p/oebb/index.js

128 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-12-18 23:24:11 +01:00
'use strict'
// todo: https://gist.github.com/anonymous/a5fc856bc80ae7364721943243f934f4#file-haf_config_base-properties-L5
// todo: https://gist.github.com/anonymous/a5fc856bc80ae7364721943243f934f4#file-haf_config_base-properties-L47-L234
2017-12-26 00:58:12 +01:00
const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask')
2018-01-07 17:24:33 +01:00
const _createParseLine = require('../../parse/line')
2017-12-29 10:01:02 +01:00
const _parseLocation = require('../../parse/location')
const _createParseMovement = require('../../parse/movement')
2017-12-26 00:58:12 +01:00
const products = require('./products')
2017-12-26 00:58:12 +01:00
2017-12-18 23:24:11 +01:00
const transformReqBody = (body) => {
2017-12-29 10:01:02 +01:00
// todo: necessary headers?
body.client = {
type: 'IPA',
id: 'OEBB',
v: '6000500',
name: 'oebbIPAD_ADHOC',
os: 'iOS 10.3.3'
}
2017-12-18 23:24:11 +01:00
// todo: https://gist.github.com/anonymous/a5fc856bc80ae7364721943243f934f4#file-haf_config_base-properties-L33 shows 1.16
2017-12-29 10:01:02 +01:00
body.ver = '1.16'
body.auth = {aid: 'OWDL4fE4ixNiPBBm'}
body.lang = 'de'
2017-12-18 23:24:11 +01:00
return body
}
2018-01-07 17:24:33 +01:00
const createParseLine = (profile, operators) => {
const parseLine = _createParseLine(profile, operators)
2017-12-29 10:01:02 +01:00
2018-01-07 17:24:33 +01:00
const parseLineWithMode = (l) => {
const res = parseLine(l)
res.mode = res.product = null
if ('class' in res) {
const data = products.bitmasks[parseInt(res.class)]
if (data) {
res.mode = data.mode
res.product = data.product
}
2017-12-29 10:01:02 +01:00
}
2018-01-07 17:24:33 +01:00
return res
}
return parseLineWithMode
2017-12-29 10:01:02 +01:00
}
const parseLocation = (profile, l) => {
// ÖBB has some 'stations' **in austria** with no departures/products,
// like station entrances, that are actually POIs.
2017-12-29 10:01:02 +01:00
const res = _parseLocation(profile, l)
if (
res.type === 'station' &&
!res.products &&
res.name &&
res.id && res.id.length !== 7
) {
return Object.assign({
2017-12-29 10:01:02 +01:00
type: 'location',
id: res.id,
name: res.name
}, res.location)
2017-12-29 10:01:02 +01:00
}
return res
}
const createParseMovement = (profile, locations, lines, remarks) => {
const _parseMovement = _createParseMovement(profile, locations, lines, remarks)
const parseMovement = (m) => {
const res = _parseMovement(m)
// filter out POIs
// todo: make use of them, as some of them specify fare zones
2017-12-29 10:01:02 +01:00
res.nextStops = res.nextStops.filter(s => s.type === 'station')
res.frames = res.frames.filter((f) => {
return f.origin.type !== 'location' && f.destination.type !== 'location'
})
2017-12-29 10:01:02 +01:00
return res
}
return parseMovement
}
const defaultProducts = {
nationalExp: true,
national: true,
interregional: true,
regional: true,
suburban: true,
bus: true,
ferry: true,
subway: true,
tram: true,
onCall: true
}
const formatBitmask = createFormatBitmask(products)
const formatProducts = (products) => {
products = Object.assign(Object.create(null), defaultProducts, products)
return {
type: 'PROD',
mode: 'INC',
value: formatBitmask(products) + ''
}
}
2017-12-18 23:24:11 +01:00
const oebbProfile = {
locale: 'de-AT',
timezone: 'Europe/Vienna',
// todo: there is also https://beta.verkehrsauskunft.at/bin/mgate.exe
endpoint: 'http://fahrplan.oebb.at/bin/mgate.exe',
2017-12-26 00:58:12 +01:00
transformReqBody,
products: products.allProducts,
2017-12-26 00:58:12 +01:00
parseProducts: createParseBitmask(products.bitmasks),
2018-01-07 17:24:33 +01:00
parseLine: createParseLine,
2017-12-29 10:01:02 +01:00
parseLocation,
parseMovement: createParseMovement,
formatProducts,
2017-12-26 00:58:12 +01:00
2017-12-29 10:01:02 +01:00
journeyLeg: true,
radar: true
2017-12-18 23:24:11 +01:00
}
module.exports = oebbProfile