Skip to content

Commit

Permalink
logging for canceled trips & remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Dec 6, 2017
1 parent f1f0047 commit 6bf3531
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
44 changes: 42 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const debug = require('debug')('vbb-hafas')

const parse = require('hafas-client/parse')
const util = require('vbb-util')
const omit = require('lodash.omit')
Expand Down Expand Up @@ -55,7 +57,43 @@ const line = (p) => {
return r
}

const journey = (l, p, r) => parse.journey('Europe/Berlin', l, p, r)
const journey = (l, p, r) => {
const parseJourney = parse.journey('Europe/Berlin', l, p, r)
const tapped = (j) => {
if (Array.isArray(j.secL)) {
for (let part of j.secL) {
if (!part) continue

// derhuerst/vbb-rest#19
if (part.dep && part.dep.dProgType) {
debug('dep.dProgType', part.dep.dProgType)
}
if (part.arr && part.arr.aProgType) {
debug('arr.aProgType', part.arr.aProgType)
}
if (part.jny && part.jny.status) {
debug('jny.status', part.jny.status)
}

// derhuerst/vbb-util#2
if (part.jny && Array.isArray(part.jny.remL)) {
for (let _ of part.jny.remL) {
const remark = {
remark: r[_.remX],
fromLoc: l[_.fLocX],
toLoc: l[_.tLocX],
fromIndex: _.fIdx,
toIndex: _.tIdx
}
debug('remark', remark)
}
}
}
}
return parseJourney(j)
}
return tapped
}

const leadingZeros = /^0+/

Expand Down Expand Up @@ -102,4 +140,6 @@ const journeyPart = (tz, s, ln, r) => (d) => {
return result
}

module.exports = {line, journey, location, nearby, journeyPart}
const remark = r => r

module.exports = {line, journey, location, nearby, journeyPart, remark}
3 changes: 2 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const onBody = (body) => {

const onLine = parse.line
const onLocation = parse.location
const onRemark = parse.remark

const request = hafas({endpoint, onBody, onLine, onLocation})
const request = hafas({endpoint, onBody, onLine, onLocation, onRemark})
module.exports = request
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vbb-hafas",
"description": "JavaScript client for the VBB HAFAS API.",
"version": "3.0.0",
"version": "3.0.1",
"main": "index.js",
"files": [
"index.js",
Expand All @@ -27,6 +27,7 @@
"node": ">=6"
},
"dependencies": {
"debug": "^3.1.0",
"got": "^7.1.0",
"hafas-client": "^1.2.0",
"lodash.omit": "^4.5",
Expand Down

0 comments on commit 6bf3531

Please sign in to comment.