Skip to content

Commit

Permalink
rest.exe client: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Oct 1, 2019
1 parent d743bd0 commit 0b8571e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
21 changes: 21 additions & 0 deletions format-rest/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const {DateTime, IANAZone} = require('luxon')

const timezones = new WeakMap()

const formatDate = (profile, when) => {
let timezone
if (timezones.has(profile)) timezone = timezones.get(profile)
else {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
}

return DateTime.fromMillis(+when, {
locale: profile.locale,
zone: timezone
}).toFormat('yyyy-MM-dd')
}

module.exports = formatDate
52 changes: 51 additions & 1 deletion rest-exe.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const parseStopover = require('./parse-rest/stopover')
const parseLocation = require('./parse-rest/location')
const parseArrivalOrDeparture = require('./parse-rest/arrival-or-departure')
const parseTrip = require('./parse-rest/trip')
const formatDate = require('./format-rest/date')
const defaultProfile = require('./lib/default-profile')
const _profile = require('./p/db')

Expand Down Expand Up @@ -97,7 +98,8 @@ const profile = {
parseJourney,
parseJourneyLeg,
parseStopover,
parseLocation
parseLocation,
formatDate
}

const opt = {
Expand Down Expand Up @@ -222,15 +224,63 @@ const trip = async (id) => {
return parseTrip(profile, opt, {})(res)
}

// todo: fails with 404
// const tripHistory = async (tripId) => {
// const res = await request('rtarchive', {
// id: tripId,
// date: profile.formatDate(profile, opt.when || Date.now())
// })
// return res
// }

// todo: fails with 404
// const radar = async (bbox) => {
// const res = await request('journeyPos', {
// llLat: bbox.south,
// llLon: bbox.west,
// urLat: bbox.north,
// urLon: bbox.east,
// // todo: operators, products, attributes, lines, jid, infotexts
// // todo: maxJny, time
// date: profile.formatDate(profile, opt.when || Date.now())
// })
// return res
// }

// todo: fails with 404
// const remarks = async () => {
// const res = await request('himSearch', {
// // todo: dateB, dateE, timeB, timeE, himIds, operators, categories
// // todo: channels, companies, metas, himcategory, poly, searchmode
// // todo: minprio, maxprio
// })
// return res
// }

// todo: fails with 404
// const dataInfo = async () => {
// const res = await request('datainfo')
// return res
// }

// journeys()
// .then(([journey]) => journey.legs.map(l => l.tripId).find(tripId => !!tripId))
// .then(trip)
// .then(tripHistory)

// locations('leopoldplatz berlin')
// nearby({type: 'location', latitude: 52.4751309, longitude: 13.3656537})
// tripAlternatives()
// departures()
// arrivals()
// radar({
// north: 52.52411,
// west: 13.41002,
// south: 52.51942,
// east: 13.41709
// })
// remarks()
// dataInfo()

.then(data => console.error(require('util').inspect(data, {depth: null, colors: true})))
.catch((err) => {
Expand Down

0 comments on commit 0b8571e

Please sign in to comment.