trip by id support

This commit is contained in:
Traines 2024-12-18 01:16:57 +00:00
parent e14a909ebf
commit 73b4d40e02
8 changed files with 305 additions and 34 deletions

View file

@ -1,15 +1,12 @@
const formatTripReq = ({opt}, id) => { const formatTripReq = ({profile, opt}, id) => {
return { return {
cfg: {polyEnc: 'GPA'}, endpoint: profile.tripEndpoint,
meth: 'JourneyDetails', path: '',
req: { query: {
// todo: getTrainComposition journeyId: id,
jid: id, poly: opt.polyline || opt.polylines,
// HAFAS apparently ignores the date in the trip ID and uses the `date` field.
// Thus, it will find a different trip if you pass the wrong date via `opt.when`.
// date: profile.formatDate(profile, opt.when),
getPolyline: Boolean(opt.polyline),
}, },
method: 'get',
}; };
}; };

View file

@ -364,13 +364,11 @@ const createClient = (profile, userAgent, opt = {}) => {
const {res} = await profile.request({profile, opt}, userAgent, req); const {res} = await profile.request({profile, opt}, userAgent, req);
const ctx = {profile, opt, common, res}; const ctx = {profile, opt, common, res};
const trip = profile.parseTrip(ctx, res.journey); const trip = profile.parseTrip(ctx, res);
return { return {
trip, trip,
realtimeDataUpdatedAt: res.planrtTS && res.planrtTS !== '0' realtimeDataUpdatedAt: null, // TODO
? parseInt(res.planrtTS)
: null,
}; };
}; };

View file

@ -3,6 +3,7 @@
"refreshJourneysEndpoint": "https://int.bahn.de/web/api/angebote/recon", "refreshJourneysEndpoint": "https://int.bahn.de/web/api/angebote/recon",
"locationsEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte", "locationsEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte",
"nearbyEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte/nearby", "nearbyEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte/nearby",
"tripEndpoint": "https://int.bahn.de/web/api/reiseloesung/fahrt",
"boardEndpoint": "https://regio-guide.de/@prd/zupo-travel-information/api/public/ri/board/", "boardEndpoint": "https://regio-guide.de/@prd/zupo-travel-information/api/public/ri/board/",
"defaultLanguage": "en" "defaultLanguage": "en"
} }

View file

@ -45,7 +45,7 @@ const parseJourneyLeg = (ctx, pt, date, fallbackLocations) => { // pt = raw leg
} }
] */ ] */
if (opt.polylines && pt.polylineGroup) { if ((opt.polylines || opt.polyline) && pt.polylineGroup) {
res.polyline = profile.parsePolyline(ctx, pt.polylineGroup); // TODO polylines not returned anymore, set "poly": true in request, apparently only works for /reiseloesung/verbindung res.polyline = profile.parsePolyline(ctx, pt.polylineGroup); // TODO polylines not returned anymore, set "poly": true in request, apparently only works for /reiseloesung/verbindung
} }

View file

@ -1,26 +1,12 @@
import minBy from 'lodash/minBy.js';
import maxBy from 'lodash/maxBy.js';
import last from 'lodash/last.js';
const parseTrip = (ctx, t) => { // t = raw trip const parseTrip = (ctx, t) => { // t = raw trip
const {profile} = ctx; const {profile} = ctx;
// pretend the trip is a leg in a journey // pretend the trip is a leg in a journey
const fakeLeg = { const trip = profile.parseJourneyLeg(ctx, t);
type: 'JNY',
dep: Array.isArray(t.stopL)
? minBy(t.stopL, 'idx') || t.stopL[0]
: {},
arr: Array.isArray(t.stopL)
? maxBy(t.stopL, 'idx') || last(t.stopL)
: {},
jny: t,
};
const trip = profile.parseJourneyLeg(ctx, fakeLeg);
trip.id = trip.tripId; // TODO journeyId trip.id = trip.tripId; // TODO journeyId
delete trip.tripId; delete trip.tripId;
delete trip.reachable; delete trip.reachable;
trip.cancelled = t.cancelled;
// TODO opt.scheduledDays // TODO opt.scheduledDays
return trip; return trip;

View file

@ -367,7 +367,7 @@ tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to S
} }
});*/ });*/
/* tap.test('trip details', async (t) => { tap.test('trip details', async (t) => {
const res = await client.journeys(berlinHbf, münchenHbf, { const res = await client.journeys(berlinHbf, münchenHbf, {
results: 1, departure: when, results: 1, departure: when,
}); });
@ -393,7 +393,7 @@ tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to S
validate(t, tripRes, 'tripResult', 'tripRes'); validate(t, tripRes, 'tripResult', 'tripRes');
t.end(); t.end();
});*/ });
tap.test('departures at Berlin Schwedter Str.', async (t) => { tap.test('departures at Berlin Schwedter Str.', async (t) => {
const res = await client.departures(blnSchwedterStr, { const res = await client.departures(blnSchwedterStr, {

File diff suppressed because one or more lines are too long

View file

@ -24,7 +24,7 @@ const createValidateRealtimeDataUpdatedAt = (cfg) => {
const createValidateProducts = (cfg) => { const createValidateProducts = (cfg) => {
const validateProducts = (val, p, name = 'products') => { const validateProducts = (val, p, name = 'products') => {
return; // TODO return; // TODO
/*a.ok(isObj(p), name + ' must be an object'); /* a.ok(isObj(p), name + ' must be an object');
for (let product of cfg.products) { for (let product of cfg.products) {
const msg = `${name}[${product.id}] must be a boolean`; const msg = `${name}[${product.id}] must be a boolean`;
a.strictEqual(typeof p[product.id], 'boolean', msg); a.strictEqual(typeof p[product.id], 'boolean', msg);