hafas-monitor-journeys

1.0.0 • Public • Published

hafas-monitor-journeys

Use any HAFAS API to monitor journeys from A to B.

npm version build status ISC-licensed chat on gitter support me on Patreon

Installing

npm install hafas-monitor-journeys

Usage

const createHafas = require('vbb-hafas')
const monitor = require('hafas-monitor-journeys')
 
const leinestr = '900000079201'
const schönleinstr = '900000016201'
 
const tasks = [{
    from: leinestr,
    to: schönleinstr,
    when: t => t, // query for the current point in time
}, {
    from: leinestr,
    to: schönleinstr,
    when: t => t + 10 * 60 * 1000 // query 10 minutes ahead
}]
 
const onJobDone = (err, journeys, job, iteration) => {
    if (err) return console.error(err)
 
    const ahead = Math.round((job.when - job.started) / 1000)
    console.log(
        'iteration ' + iteration,
        ahead + 's ahead',
        journeys.length + ' journeys'
    )
}
 
const onEnd = (iteration) => {
    console.log('iteration ' + iteration + ' done')
}
 
const hafas = createHafas('my-awesome-program')
const run = monitor(hafas.journeys, tasks)
run(onJobDone, onEnd)
iteration 1 0s ahead 5 journeys
iteration 1 600s ahead 5 journeys
iteration 1 done

Contributing

If you have a question or have difficulties using hafas-monitor-journeys, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.

Package Sidebar

Install

npm i hafas-monitor-journeys

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

6.3 kB

Total Files

5

Last publish

Collaborators

  • derhuerst