From c663a357119d8595c748b15167933ec0ba2646a8 Mon Sep 17 00:00:00 2001 From: Traines Date: Tue, 10 Dec 2024 17:51:20 +0000 Subject: [PATCH] switch to regio-guide ris for boards --- format/station-board-req.js | 20 ++++++++++++++++++++ index.js | 2 +- p/db/base.json | 2 +- parse/arrival-or-departure.js | 12 ++++++------ parse/line.js | 10 +++++----- parse/location.js | 4 ++-- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/format/station-board-req.js b/format/station-board-req.js index 68ad26bc..acc93fb5 100644 --- a/format/station-board-req.js +++ b/format/station-board-req.js @@ -1,6 +1,25 @@ const formatStationBoardReq = (ctx, station, type) => { const {profile, opt} = ctx; + return { + endpoint: profile.boardEndpoint, + path: (type == 'departures' ? 'departure' : 'arrival') + '/' + station, + query: { + // TODO direction, fields below + modeOfTransport: profile.formatProductsFilter(ctx, opt.products || {}, 'ris'), + timeStart: profile.formatTime(profile, opt.when, true), + timeEnd: profile.formatTime(profile, opt.when.getTime() + opt.duration * 60 * 1000, true), + expandTimeFrame: 'TIME_END', // TODO impact? + }, + method: 'get', + }; +}; + +/* +TODO separate RIS::Boards profile? +const formatRisStationBoardReq = (ctx, station, type) => { + const {profile, opt} = ctx; + return { endpoint: profile.boardEndpoint, path: type + '/' + station, @@ -23,6 +42,7 @@ const formatStationBoardReq = (ctx, station, type) => { }, }; }; +*/ export { formatStationBoardReq, diff --git a/index.js b/index.js index 7836e8a9..7e06fa4f 100644 --- a/index.js +++ b/index.js @@ -89,7 +89,7 @@ const createClient = (profile, userAgent, opt = {}) => { const {res, common} = await profile.request({profile, opt}, userAgent, req); const ctx = {profile, opt, common, res}; - const results = res[resultsField].map(res => parse(ctx, res)); // todo sort? + const results = (res[resultsField] || res.items).map(res => parse(ctx, res)); // todo sort? return { [resultsField]: results, diff --git a/p/db/base.json b/p/db/base.json index f0bfd818..0a1bea97 100644 --- a/p/db/base.json +++ b/p/db/base.json @@ -2,6 +2,6 @@ "journeysEndpoint": "https://int.bahn.de/web/api/angebote/fahrplan", "locationsEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte", "nearbyEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte/nearby", - "boardEndpoint": "https://apis.deutschebahn.com/db/apis/ris-boards/v1/public/", + "boardEndpoint": "https://regio-guide.de/@prd/zupo-travel-information/api/public/ri/board/", "defaultLanguage": "en" } diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 05d608b7..82f18c62 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -14,15 +14,15 @@ const createParseArrOrDep = (prefix) => { const res = { tripId: d.journeyID, stop: profile.parseLocation(ctx, d.station), - ...profile.parseWhen(ctx, null, d.timeSchedule, d.time, d.canceled), - ...profile.parsePlatform(ctx, d.platformSchedule, d.platform, d.canceled), + ...profile.parseWhen(ctx, null, d.timeSchedule ? d.timeSchedule : d.time, d.timePredicted ? d.timePredicted : d.time, d.canceled), + ...profile.parsePlatform(ctx, d.platformSchedule ? d.platformSchedule : d.platform, d.platformPredicted ? d.platformPredicted : d.platform, d.canceled), // prognosisType: TODO - direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || null, - provenance: profile.parseStationName(ctx, d.transport?.origin?.name) || null, + direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || profile.parseStationName(ctx, d.destination?.name) || null, + provenance: profile.parseStationName(ctx, d.transport?.origin?.name) || profile.parseStationName(ctx, d.origin?.name) || null, line: profile.parseLine(ctx, d) || null, remarks: [], - origin: profile.parseLocation(ctx, d.transport?.origin) || null, - destination: profile.parseLocation(ctx, d.transport?.destination) || null, + origin: profile.parseLocation(ctx, d.transport?.origin || d.origin) || null, + destination: profile.parseLocation(ctx, d.transport?.destination || d.destination) || null, }; // TODO pos diff --git a/parse/line.js b/parse/line.js index 27ecdd34..cf1e3c57 100644 --- a/parse/line.js +++ b/parse/line.js @@ -4,15 +4,15 @@ const parseLine = (ctx, p) => { const profile = ctx.profile; const res = { type: 'line', - id: slugg(p.verkehrsmittel?.langText || p.transport?.journeyDescription), // TODO terrible - fahrtNr: p.verkehrsmittel?.nummer || p.transport?.number, - name: p.verkehrsmittel?.name || p.zugName || p.transport?.journeyDescription, + id: slugg(p.verkehrsmittel?.langText || p.transport?.journeyDescription || p.train?.no), // TODO terrible + fahrtNr: p.verkehrsmittel?.nummer || p.transport?.number || p.train?.no, + name: p.verkehrsmittel?.name || p.zugName || p.transport?.journeyDescription || p.train && p.train.category + ' ' + p.train.lineName, public: true, }; // TODO res.adminCode - res.productName = p.verkehrsmittel?.kurzText || p.transport?.category; - const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type); + res.productName = p.verkehrsmittel?.kurzText || p.transport?.category || p.train?.category; + const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type || pp.ris == p.train?.type); res.mode = foundProduct?.mode; res.product = foundProduct?.id; diff --git a/parse/location.js b/parse/location.js index 89923dae..83adb798 100644 --- a/parse/location.js +++ b/parse/location.js @@ -16,7 +16,7 @@ const parseLocation = (ctx, l) => { const lid = parse(l.id, {delimiter: '@'}); const res = { type: 'location', - id: (l.extId || lid.L || l.evaNumber || '').replace(leadingZeros, '') || null, + id: (l.extId || lid.L || l.evaNumber || l.evaNo || '').replace(leadingZeros, '') || null, }; if (l.lat && l.lon) { @@ -27,7 +27,7 @@ const parseLocation = (ctx, l) => { res.longitude = lid.X / 1000000; } - if (l.type === STATION || l.extId || l.evaNumber) { + if (l.type === STATION || l.extId || l.evaNumber || l.evaNo) { const stop = { type: 'stop', // TODO station id: res.id,