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

72 lines
2 KiB
JavaScript
Raw Permalink Normal View History

2022-05-07 16:17:37 +02:00
// 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);
2017-12-18 23:24:11 +01:00
// 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
import {parseHook} from '../../lib/profile-hooks.js';
2017-12-26 00:58:12 +01:00
import {parseLocation as _parseLocation} from '../../parse/location.js';
import {parseMovement as _parseMovement} from '../../parse/movement.js';
const baseProfile = require('./base.json');
import {products} from './products.js';
2017-12-26 00:58:12 +01:00
2019-10-20 00:19:52 +02:00
// ÖBB has some 'stations' **in austria** with no departures/products,
// like station entrances, that are actually POIs.
const fixWeirdPOIs = ({parsed}) => {
if (
(parsed.type === 'station' || parsed.type === 'stop')
&& !parsed.products
&& parsed.name
&& parsed.id && parsed.id.length !== 7
) {
return Object.assign({
2017-12-29 10:01:02 +01:00
type: 'location',
2019-10-20 00:19:52 +02:00
id: parsed.id,
poi: true,
name: parsed.name,
}, parsed.location);
2017-12-29 10:01:02 +01:00
}
return parsed;
};
2017-12-29 10:01:02 +01:00
2019-10-20 00:19:52 +02:00
const fixMovement = ({parsed}, m) => {
// filter out POIs
// todo: make use of them, as some of them specify fare zones
parsed.nextStopovers = parsed.nextStopovers.filter(st => {
let s = st.stop || {};
if (s.station) {
s = s.station;
}
return s.type === 'stop' || s.type === 'station';
});
2019-10-20 00:19:52 +02:00
parsed.frames = parsed.frames.filter((f) => {
return f.origin.type !== 'location' && f.destination.type !== 'location';
});
return parsed;
};
2017-12-29 10:01:02 +01:00
2022-05-07 16:17:37 +02:00
const profile = {
...baseProfile,
2017-12-18 23:24:11 +01:00
locale: 'de-AT',
timezone: 'Europe/Vienna',
defaultLanguage: 'de',
2017-12-26 00:58:12 +01:00
products: products,
2017-12-26 00:58:12 +01:00
2019-10-20 00:19:52 +02:00
parseLocation: parseHook(_parseLocation, fixWeirdPOIs),
parseMovement: parseHook(_parseMovement, fixMovement),
2017-12-29 10:01:02 +01:00
refreshJourneyUseOutReconL: true,
trip: true,
2018-08-26 18:35:27 +02:00
radar: true,
2020-09-16 17:21:59 +02:00
reachableFrom: true,
2021-12-02 13:56:56 +01:00
// lines: false, // `.svcResL[0].res.lineL[]` is missing 🤔
};
2017-12-18 23:24:11 +01:00
2022-05-07 16:17:37 +02:00
export {
profile,
};