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

87 lines
2 KiB
JavaScript
Raw Normal View History

2018-03-14 14:54:08 +01:00
'use strict'
2019-10-20 00:19:52 +02:00
const {parseHook} = require('../../lib/profile-hooks')
2018-03-14 14:54:08 +01:00
2019-10-20 00:19:52 +02:00
const _parseLocation = require('../../parse/location')
const _parseJourney = require('../../parse/journey')
const _parseMovement = require('../../parse/movement')
const baseProfile = require('./base.json')
2018-03-14 14:54:08 +01:00
const products = require('./products')
// todo: journey prices
2019-10-20 00:19:52 +02:00
const fixLocation = ({parsed}, l) => {
2018-03-14 14:54:08 +01:00
// weird fix for empty lines, e.g. IC/EC at Flensburg Hbf
2019-10-20 00:19:52 +02:00
if (parsed.lines) {
parsed.lines = parsed.lines.filter(x => x.id && x.name)
2018-03-14 14:54:08 +01:00
}
2018-03-18 13:00:16 +01:00
// remove leading zeroes, todo
2019-10-20 00:19:52 +02:00
if (parsed.id && parsed.id.length > 0) {
parsed.id = parsed.id.replace(/^0+/, '')
2018-03-14 14:54:08 +01:00
}
2019-10-20 00:19:52 +02:00
return parsed
2018-03-14 14:54:08 +01:00
}
2019-10-20 00:19:52 +02:00
const parseJourneyWithTickets = ({parsed}, j) => {
if (
j.trfRes &&
Array.isArray(j.trfRes.fareSetL) &&
j.trfRes.fareSetL.length > 0
) {
parsed.tickets = []
for (let t of j.trfRes.fareSetL) {
const tariff = t.desc
if (!tariff || !Array.isArray(t.fareL)) continue
for (let v of t.fareL) {
const variant = v.name
if(!variant) continue
const ticket = {
name: [tariff, variant].join(' - '),
tariff,
variant
}
if (v.prc && Number.isInteger(v.prc) && v.cur) {
ticket.amount = v.prc/100
ticket.currency = v.cur
} else {
ticket.amount = null
ticket.hint = 'No pricing information available.'
2018-03-15 09:33:31 +01:00
}
2019-10-20 00:19:52 +02:00
parsed.tickets.push(ticket)
2018-03-15 09:33:31 +01:00
}
}
}
2019-10-20 00:19:52 +02:00
return parsed
2018-03-15 09:33:31 +01:00
}
2019-10-20 00:19:52 +02:00
const fixMovement = ({parsed}, m) => {
// filter out empty nextStopovers entries
parsed.nextStopovers = parsed.nextStopovers.filter((f) => {
return f.stop !== null || f.arrival !== null || f.departure !== null
})
return parsed
2018-03-14 14:54:08 +01:00
}
const nahshProfile = {
...baseProfile,
2018-03-14 14:54:08 +01:00
locale: 'de-DE',
timezone: 'Europe/Berlin',
2018-03-21 01:42:13 +01:00
products,
2018-03-14 14:54:08 +01:00
2019-10-20 00:19:52 +02:00
parseLocation: parseHook(_parseLocation, fixLocation),
parseJourney: parseHook(_parseJourney, parseJourneyWithTickets),
parseMovement: parseHook(_parseMovement, fixMovement),
2018-03-14 14:54:08 +01:00
refreshJourneyUseOutReconL: true,
trip: true,
radar: true,
2020-09-16 17:21:59 +02:00
reachableFrom: true,
2018-03-14 14:54:08 +01:00
}
module.exports = nahshProfile