Skip to content

Commit 0b8cf9e

Browse files
committed
rest.exe: arrivals() via stationBoard()
1 parent f0e4110 commit 0b8cf9e

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

parse-rest/arrival-or-departure.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
const DEPARTURE = 'departure'
4-
const ARRIVAL = 'arrival'
5-
63
// todo: d.JourneyStatus
74
// todo: d.Notes
85
// todo: d.prognosisType
@@ -25,7 +22,7 @@ const createParseArrOrDep = (profile, opt, data, type) => {
2522
extId: d.stopExtId
2623
}),
2724
line: profile.parseLine(profile, opt, data)(product) || null,
28-
direction: type === DEPARTURE && d.direction || null,
25+
direction: type === 'departure' && d.direction || null, // todo: arrivals
2926
// todo: is there `d.rtDate` & `d.tz` & `d.rtTz`?
3027
...profile.parseWhen(profile, d.date, null, d.time, d.rtTime, null, !!d.cancelled),
3128
platform: d.track || null

rest-exe.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const profile = {
107107
parseJourney,
108108
parseJourneyLeg,
109109
parseStopover,
110+
parseArrivalOrDeparture,
110111
parseLocation,
111112
formatDate,
112113
formatTime
@@ -263,19 +264,20 @@ const tripAlternatives = async (tripCtx, origin, destination) => {
263264
return res.Trip.map(parseJourney(profile, opt))
264265
}
265266

266-
const departures = async (stop, opt = {}) => {
267+
const _stationBoard = async (method, stop, opt) => {
267268
const stopId = 'string' === typeof stop ? stop : stop.id
268269
if ('string' !== typeof stopId) {
269270
throw new TypeError('stop must be a stop object or a string.')
270271
}
271272

272273
opt = {
273-
direction: null, // only show departures stopping by this station
274-
duration: 10, // show departures for the next n minutes
275-
results: null, // number of departures – `null` means "whatever HAFAS returns"
274+
// todo: for arrivals(), this is actually a station it *has already* stopped by
275+
direction: null, // only show arrivals/departures stopping by this station
276+
duration: 10, // show arrivals/departures for the next n minutes
277+
results: null, // number of arrivals/departures – `null` means "whatever HAFAS returns"
276278
products: {}, // enabled/disable certain products to search for
277279
remarks: true, // parse & expose hints & warnings?
278-
// departures at related stations
280+
// arrivals/departures at related stations
279281
// e.g. those that belong together on the metro map.
280282
includeRelatedStations: true,
281283
...opt
@@ -304,20 +306,23 @@ const departures = async (stop, opt = {}) => {
304306
query.date = profile.formatDate(profile, when)
305307
query.time = profile.formatTime(profile, when)
306308

307-
const res = await request('departureBoard', query)
308-
const parse = parseArrivalOrDeparture(profile, opt, {})
309-
return res.departureAndMessage ? res.departureAndMessage.map(d => parse(d.Departure)) : []
309+
return await request(method, query)
310310
}
311311

312-
const arrivals = async (stop) => {
313-
const res = await request('arrivalBoard', {
314-
extId: '8000152',
315-
// todo: direction, date, time, duration, products, operators, lines
316-
// todo: maxJourneys, filterEquiv, attributes, rtMode
317-
})
312+
const departures = async (stop, opt = {}) => {
313+
const res = await _stationBoard('departureBoard', stop, opt)
314+
const results = res.departureAndMessage || []
315+
316+
const parse = profile.parseArrivalOrDeparture(profile, opt, {}, 'departure')
317+
return results.map(result => parse(result.Departure))
318+
}
319+
320+
const arrivals = async (stop, opt = {}) => {
321+
const res = await _stationBoard('arrivalBoard', stop, opt)
322+
const results = res.arrivalAndMessage || []
318323

319-
const parse = parseArrivalOrDeparture(profile, opt, {})
320-
return res.arrivalAndMessage.map(d => parse(d.Arrival))
324+
const parse = profile.parseArrivalOrDeparture(profile, opt, {}, 'arrival')
325+
return results.map(result => parse(result.Arrival))
321326
}
322327

323328
const trip = async (id) => {

0 commit comments

Comments
 (0)