Giter Site home page Giter Site logo

baahn's Introduction

Baahn! ๐Ÿš‚

baahn lets you find special connections saving money when travelling with Deutsche Bahn (DB). It's using hafas-client (huge thanks!) under the hood for fetching information about journeys.

Suppose you plan to travel from Berlin Hbf to Magdeburg Hbf. This package finds a longer journey containing the actual journey from Berlin to Magdeburg but which is cheaper (yep, the DB price system is weeeird).

The output of the baahn web app:

baahn web app in action

Installation

npm i @roehrt/baahn

Example

const { findJourneys } = require('@roehrt/baahn');
findJourneys('8011160', '8010224').then((data) => {
  console.log(require('util').inspect(data, {depth: null, colors: true}))
});

For finding the station ids hafas-client is recommended. For everyday use consider using the baahn-cli package.

More information on how to use findJourneys can be found in the hafas-client docs: journeys and findJourneys have the same signature and nearly the same return type and can therefore be used interchangeably. The only additional property that findJourneys return is an optional object trick storing how the price saving was achieved.

interface BaahnJourney extends Journey {
  trick?: {
    prepend: Leg[],
    append: Leg[],
    oldPrice: number,
  }
}
  • oldPrice stores the unoptimized price.
  • prepend stores all legs that need to be prepended to the original journey.
  • append stores all legs that need to be appended to the original journey.

Known Problems

baahn uses a graph of long-distance train stations, so it won't find many tricks if the origin or destination is a non-long-distance station. In fact if both - origin and destination - are non-long-distance stations the search will never respond with an improved price since the stations are missing in the adjacency list (stationGraph.json).

The graph may be merged with this edge list in the future.

For further information visit the rather spartan FAQ (German).

See Also

baahn-cli - a simple cli wrapper for this module.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.