Giter Site home page Giter Site logo

lvbb'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.

lvbb's People

Contributors

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

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.