diff --git a/docs/departures.md b/docs/departures.md index 26c52c92..ed2f15ca 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -29,6 +29,7 @@ With `opt`, you can override the default options, which look like this: duration: 10, // show departures for the next n minutes stationLines: false, // parse & expose lines of the station? remarks: true, // parse & expose hints & warnings? + stopovers: false, // fetch & parse previous/next stopovers? // departures at related stations // e.g. those that belong together on the metro map. includeRelatedStations: true, diff --git a/index.js b/index.js index 244da13b..9dd32f49 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,7 @@ const createClient = (profile, userAgent, request = _request) => { duration: 10, // show departures for the next n minutes stationLines: false, // parse & expose lines of the station? remarks: true, // parse & expose hints & warnings? + stopovers: false, // fetch & parse previous/next stopovers? // departures at related stations // e.g. those that belong together on the metro map. includeRelatedStations: true @@ -73,7 +74,7 @@ const createClient = (profile, userAgent, request = _request) => { dirLoc: dir, jnyFltrL: [products], dur: opt.duration, - getPasslist: false, // todo + getPasslist: !!opt.stopovers, stbFltrEquiv: !opt.includeRelatedStations } }) diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 772d402f..a1c39493 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -63,6 +63,14 @@ const createParseArrOrDep = (profile, opt, data, prefix) => { .filter(rem => !!rem) // filter unparsable } + if (opt.stopovers && d.stopL) { + const parse = profile.parseStopover(profile, opt, data, d.date) + // Filter stations the train passes without stopping, as this doesn't comply with FPTF (yet). + const stopovers = d.stopL.map(parse).filter(st => !st.passBy) + if (prefix === ARRIVAL) res.previousStopovers = stopovers + else if (prefix === DEPARTURE) res.nextStopovers = stopovers + } + return res }