Giter Site home page Giter Site logo

lvb's Introduction

lvb

Client for the LVB (Leipziger Verkehrsbetriebe) API. Inofficial, please ask LVB for permission before using this module in production. Actually, there should be no need for projects like this since municipal public transportation endpoints should be open to the public. It's 2021.

npm version license

Installation

npm install --save lvb

Usage

This package mostly returns data in the Friendly Public Transport Format:

stations(query, [opt])

Using lvb.stations, you can query stations operated bei LVB.

const stations = require('lvb').stations

stations('Nationalbibliothek').then(console.log)

Returns a Promise that will resolve in an array of stations in the Friendly Public Transport Format which looks as follows:

[
    {
        "id": "11558",
        "type": "station",
        "name": "Leipzig, Deutsche Nationalbibliothek",
        "coordinates": {
            "longitude": 12.396131411662,
            "latitude": 51.323542325868
        }
    }
    // …
]

defaults, partially overridden by the opt parameter, looks as follows:

const defaults = {
    limit: 5 // Maximum number of returned results. CAUTION: Because of something unlucky that happens to station ids in the API, a `stations` request will spawn (number of results + 1) requests. Keep this in mind when increasing this threshold.
}

departures(station, date = Date.now())

Using lvb.departures, you can get departures at a given station for a specific date and time.

const departures = require('lvb').departures

const Nationalbibliothek = '11558'

departures(Nationalbibliothek, new Date())

Returns a Promise that will resolve in a list of objects (one object per direction per line) like this:

[
    {
        "line": {
            "id": "16",
            "name": "Str   16", // yeah, that really looks like this :/
            "class": "StN",
            "operator": "LVB",
            "direction": "Lößnig über Connewitz, Kreuz"
        },
        "timetable": [
            {
                "departure": "2017-10-09T16:09:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:19:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:29:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:39:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:51:00.000Z", // JS Date() object
                "departureDelay": 0
            }
        ]
    }
    // …
]

journeys(origin, destination, date = Date.now(), [opt])

Using lvb.journeys, you can get directions and prices for routes from A to B.

const journeys = require('lvb').journeys

journeys(origin, destination, date = Date.now(), opt = defaults)

const Nationalbibliothek = '11558'
const Messe = '10818'
const date = new Date()

journeys(Nationalbibliothek, Messe, date)
.then(console.log)
.catch(console.error)

Returns a Promise that will resolve with an array of journeys in the Friendly Public Transport Format which looks as follows. Note that the legs are not (fully) spec-compatible, as the schedule is missing (see the line and route keys instead).

[
    {
        "type": "journey",
        "id": "Leipzig, Deutsche Nationalbibliothek@20171009173100@Leipzig, Wilhelm-Leuschner-Platz@20171009173900@SEV16@BUN-Leipzig, Wilhelm-Leuschner-Platz@20171009174200@Leipzig, Messegelände@20171009180800@16@STN",
        "legs": [
            {
                "origin": {
                    "type": "station",
                    "name": "Leipzig, Deutsche Nationalbibliothek",
                    "id": 11558,
                    "coordinates": {
                        "longitude": 12.395702,
                        "latitude": 51.32357
                    }
                },
                "destination": {
                    "type": "station",
                    "name": "Leipzig, Wilhelm-Leuschner-Platz",
                    "id": 12992,
                    "coordinates": {
                        "longitude": 12.375872,
                        "latitude": 51.335876
                    }
                },
                "line": {
                    "id": "SEV16",
                    "class": "BUN",
                    "direction": "Wilhelm-Leuschner-Platz",
                    "operator": "Leipziger Verkehrsbetriebe",
                    "color": "#017C46"
                },
                "route": [
                    {
                        "type": "station",
                        "id": 11558,
                        "name": "Leipzig, Deutsche Nationalbibliothek",
                        "coordinates": {
                            "longitude": 12.395702,
                            "latitude": 51.32357
                        }
                    },
                    {
                        "type": "station",
                        "id": 11557,
                        "name": "Leipzig, Johannisallee",
                        "coordinates": {
                            "longitude": 12.388807,
                            "latitude": 51.327309
                        }
                    }
                    // …
                ],
                "departure": "2017-10-09T15:31:00.000Z", // JS Date() object
                "departureDelay": 0,
                "arrival": "2017-10-09T15:39:00.000Z", // JS Date() object
                "arrivalDelay": 0,
                "departurePlatform": null,
                "arrivalPlatform": null
            },
            {
                "origin": {
                    "type": "station",
                    "name": "Leipzig, Wilhelm-Leuschner-Platz",
                    "id": 12992,
                    "coordinates": {
                        "longitude": 12.375872,
                        "latitude": 51.335876
                    }
                },
                "destination": {
                    "type": "station",
                    "name": "Leipzig, Messegelände",
                    "id": 10818,
                    "coordinates": {
                        "longitude": 12.396583,
                        "latitude": 51.396724
                    }
                },
                "line": {
                    "id": "16",
                    "class": "STN",
                    "direction": "Messegelände",
                    "operator": "Leipziger Verkehrsbetriebe",
                    "color": "#017C46"
                },
                "route": [
                    {
                        "type": "station",
                        "id": 12992,
                        "name": "Leipzig, Wilhelm-Leuschner-Platz",
                        "coordinates": {
                            "longitude": 12.375872,
                            "latitude": 51.335876
                        }
                    },
                    {
                        "type": "station",
                        "id": 13002,
                        "name": "Leipzig, Augustusplatz",
                        "coordinates": {
                            "longitude": 12.382012,
                            "latitude": 51.338905
                        }
                    }
                    // …
                ],
                "departure": "2017-10-09T15:42:00.000Z", // JS Date() object
                "departureDelay": 0,
                "arrival": "2017-10-09T16:08:00.000Z", // JS Date() object
                "arrivalDelay": 0,
                "departurePlatform": null,
                "arrivalPlatform": null
            }
        ],
        "price": {
            "model": "Einzelfahrkarte",
            "amount": 2.6,
            "currency": "EUR",
            "fares": [
                {
                    "type": "fare",
                    "model": "Einzelfahrkarte",
                    "amount": 2.6,
                    "currency": "EUR"
                },
                {
                    "type": "fare",
                    "model": "Einzelfahrkarte Kind",
                    "amount": 1.2,
                    "currency": "EUR"
                },
                {
                    "type": "fare",
                    "model": "4-Fahrten-Karte",
                    "amount": 10.4,
                    "currency": "EUR"
                }
                // …
            ]
        },
        "zones": {
            "departure": "110",
            "arrival": "110",
            "list": "110"
        }
    }
    // …
]

defaults, partially overridden by the opt parameter, looks like this:

const defaults = {
    via: null // station id
}

See also

  • FPTF - "Friendly public transport format"
  • FPTF-modules - modules that also use FPTF

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.

lvb's People

Contributors

greenkeeper[bot] avatar hashworks avatar jervistetch avatar joergreichert avatar juliuste avatar sibbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lvb's Issues

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.15.2 to 5.15.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v5.15.3
  • 71adc66 Fix: avoid moving comments in implicit-arrow-linebreak (fixes #11521) (#11522) (Teddy Katz)
  • 1f715a2 Chore: make test-case-property-ordering reasonable (#11511) (Toru Nagashima)
Commits

The new version differs by 4 commits.

  • a6168f8 5.15.3
  • cb57316 Build: changelog update for 5.15.3
  • 71adc66 Fix: avoid moving comments in implicit-arrow-linebreak (fixes #11521) (#11522)
  • 1f715a2 Chore: make test-case-property-ordering reasonable (#11511)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

FetchError: Maybe LVB has changed their Site again

Hi. I am facing following error
errorFetchError: invalid json response body at https://www.l.de/verkehrsbetriebe/fahrplan/haltestelle reason: Unexpected token < in JSON at position 0

while I try to execude this code:

const server = http.createServer((req, res) => {
        res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
        departures('"some valid number"'
        , new Date(new Date().getTime() - 30*60000)).then((connections) => {
                res.end(JSON.stringify(connections));
                }).catch(function(reason) {
                console.log("---------------------");
                console.log("error" + reason);
                console.log("---------------------");
        });
});

The Error occurs since 27.10.2020, evening.

I had a similar issue like two months ago and I solved by using the newesst version of this repo. But this time there are no new version, so I thougth, I should open a new ticket.

I am thankfull for any help or ideas or maybe the error can be solved by time.

Best reagards, Tobi.

LVB API no longer uses IDs

Looks like the LVB API no longer provides station IDs in the AJAX response:

$ curl https://www.l.de/ajax_de?mode=autocomplete&q=Herman&poi=&limit=10
{"stations":[{"name":"Leipzig, Hermann-Liebmann-Str.\/ Eisenbahnstr.","lat":"51.345578950648","lng":"12.406472923894","distance":"2.272732820253887"},{"name":"Leipzig, Dr.-Hermann-Duncker-Str.","lat":"51.333249688312","lng":"12.305794850988","distance":"4.849646498628953"}]}

/fahrplan/abfahrten now uses the whole name instead:
request

The lvb.departures test is wrong at that point: Providing the ID results in the departures of a different station.

Departures gives JSON error

import { departures } from "lvb"
const d = await departures("12714", Date.now())

Station is Hermann-Liebmann-Str./Eisenbahnstr.

FetchError: invalid json response body at https://www.l.de/verkehrsbetriebe/fahrplan/ reason: Unexpected token < in JSON at position 0
    at /path/node_modules/node-fetch/lib/index.js:272:32
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at path/file.ts:38:19 {
  type: 'invalid-json'

Maybe they changed the API.

get all stations from the API

Hi there,

is it possible to get all single stations from the API?

I want to implement this in Node Red and select the stations via dropdown.

Kind regards Alex

An in-range update of tape is breaking the build 🚨

The devDependency tape was updated from 4.10.0 to 4.10.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 4 commits.

  • 4708a3d v4.10.1
  • a63261e [Deps] update resolve
  • 34ebb4c [Refactor] consistent spacing
  • b74c4fd Partial revert of #403: fbe4b951cb6c6cc4f0e9e3ae4a57b123dd82c0fb and 367b010d21c7c9814c4bc6b21d1c2a9a67596c11

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of moment-timezone is breaking the build 🚨

The dependency moment-timezone was updated from 0.5.21 to 0.5.22.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

moment-timezone is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for Release 0.5.22
  • Updated data to IANA TZDB 2018g #689
  • Fix issue with missing LMT entries for some zones, and fix data builds on Linux and Windows #308
Commits

The new version differs by 12 commits ahead by 12, behind by 2.

  • 1a8a2a2 Merge pull request #690 from mj1856/develop
  • 78ebaa9 Build release 0.5.22
  • 17144d5 Rebuild tests for 2018g
  • b611d51 Fix path with tests on windows
  • 01f1f1e Rebuild 2018g/latest data with zdump fixes in place
  • 07978c4 Fix issue with zdump output on non-Mac systems
  • 2cd3adc Copy 2018g to latest
  • a43ca15 Update tzdata download url
  • 208874f Merge pull request #689 from alaouy/develop
  • 58e0f8c Added 2018g timezones data set
  • 2445c79 Bugfix: revert breaking change
  • 3e85105 Bugfix: revert breaking change

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Exception when querying for journeys

Querying for Journeys for example between Westplatz and Willhelm-Leuschner-Platz leads to problems. Writing this code

const journey_q = require("lvb").journeys;
journey_q("11005", '12992', new Date()).then(console.log);

throws this exception

(node:19806) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tickets' of null
    at transformTariffs (/home/bastian/Desktop/Programs/takemehome/node_modules/lvb/lib/journeys.js:73:11)
    at transformJourney (/home/bastian/Desktop/Programs/takemehome/node_modules/lvb/lib/journeys.js:89:9)
    at Array.map (<anonymous>)
    at /home/bastian/Desktop/Programs/takemehome/node_modules/lvb/lib/journeys.js:144:22
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:19806) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19806) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can I just turn off ticketing information, as I don't need it for my application?

An in-range update of depcheck is breaking the build 🚨

The devDependency depcheck was updated from 0.9.0 to 0.9.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

depcheck is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for The one with a bunch of features

Features

  • better support for workspaces #473
  • support for prettier shared configuration #474
  • support for typescript webpack configuration #459
  • added support for ttypescript #469
  • typescript types! #458
  • added support for lint-staged #456
  • added support for husky #453
  • added support for babel.config.js

Bugfixes

  • consitent exit code #465
  • fixed false positive when using plugin:prettier/recommended #464
  • fixed false positive when using tslint-plugin-prettier #457

Big thanks to @VincentLanglet and @sveyret

I almost made this 1.0.0 but it will be for the next.

Commits

The new version differs by 41 commits.

  • 5e2ae0d Merge pull request #473 from sveyret/noderesolve
  • 6d1d3b8 Use node resolution for dependencies
  • 55622db Merge pull request #474 from sveyret/prettier
  • 671b053 Support prettier shared configuration
  • dcb186f Merge pull request #470 from sveyret/AutoTS
  • 004397b Automate building of TypeScript definitions
  • 64ebbfc Merge pull request #459 from sveyret/loadTS
  • c824eb8 Load typescript transpiler if available
  • d2057a0 Merge pull request #469 from sveyret/TTypeScript
  • 77b4b12 Add TTypeScript transformer special parser
  • 103adab Merge pull request #467 from depcheck/chore-node-10
  • aabf02f chore: update node requirement in package.json and readme
  • 279fb1b Merge pull request #466 from depcheck/chore-more-stale
  • b8f2122 Merge branch 'master' into chore-more-stale
  • dff7ebb Merge pull request #465 from depcheck/feat-consistent-exit-code

There are 41 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.