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 {
cfg: {polyEnc: 'GPA'},
meth: 'JourneyDetails',
req: {
// todo: getTrainComposition
jid: id,
// 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),
endpoint: profile.tripEndpoint,
path: '',
query: {
journeyId: id,
poly: opt.polyline || opt.polylines,
},
method: 'get',
};
};

View file

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

View file

@ -3,6 +3,7 @@
"refreshJourneysEndpoint": "https://int.bahn.de/web/api/angebote/recon",
"locationsEndpoint": "https://int.bahn.de/web/api/reiseloesung/orte",
"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/",
"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
}

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 {profile} = ctx;
// pretend the trip is a leg in a journey
const fakeLeg = {
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);
const trip = profile.parseJourneyLeg(ctx, t);
trip.id = trip.tripId; // TODO journeyId
delete trip.tripId;
delete trip.reachable;
trip.cancelled = t.cancelled;
// TODO opt.scheduledDays
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, {
results: 1, departure: when,
});
@ -393,7 +393,7 @@ tap.skip('journeysFromTrip U Mehringdamm to U Naturkundemuseum, reroute to S
validate(t, tripRes, 'tripResult', 'tripRes');
t.end();
});*/
});
tap.test('departures at Berlin Schwedter Str.', async (t) => {
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 validateProducts = (val, p, name = 'products') => {
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) {
const msg = `${name}[${product.id}] must be a boolean`;
a.strictEqual(typeof p[product.id], 'boolean', msg);