🚊 Query Dresden's public transport system for current bus- and tramstop data in node
JavaScript
Clone or download
Latest commit 2df6070 Oct 16, 2017
Permalink
Failed to load latest commit information.
lib remove route, update dependencies Oct 16, 2017
test remove route, update dependencies Oct 16, 2017
.coveralls.yml update dependancies, travis, coveralls, add contributor Jens Maus Feb 17, 2017
.gitignore fix test file capital letter Mar 16, 2017
.travis.yml remove route, update dependencies Oct 16, 2017
LICENSE
README.md fix readme: remove route Oct 16, 2017
index.js remove route, update dependencies Oct 16, 2017
package.json 4.3.7 Oct 16, 2017

README.md

dvbjs

travis-ci Coverage Status npmversion Downloads

NPM

This is an unofficial node module, giving you a few options to query Dresden's public transport system for current bus- and tramstop data.

Want something like this for another language, look no further 🙂

Getting Started

Install the module using npm

$ npm install dvbjs

and require it in your project

var dvb = require('dvbjs');

API Documentation

All dvbjs functions use callbacks and return a Promise:

dvb.find('zellesch', function(err, data){
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

// or:

dvb.find('zellesch')
    .then(function (data) {
        console.log(JSON.stringify(data, null, 4));
    })
    .catch(function (err) {
        throw err;
    });

Monitor a single stop

Monitor a single stop to see every bus or tram leaving this stop after the specified time offset.

Example:

var stop = 33000037;        // ID of the stop
// var stop = 'Postplatz';  // or name of the stop (must be unambiguous)
var timeOffset = 0; // how many minutes in the future, 0 for now
var numResults = 2; // number of results

dvb.monitor(stop, timeOffset, numResults, function(err, data) {
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

Output:

[
    {
        "line": "8",
        "direction": "Südvorstadt",
        "platform": {
            "name": "3",
            "type": "Platform"
        },
        "arrivalTime": "2017-02-17T22:22:00.000Z",
        "arrivalTimeRelative": 0,
        "scheduledTime": "2017-02-17T22:22:00.000Z",
        "scheduledTimeRelative": 0,
        "delayTime": 0,
        "state": "InTime",
        "mode": {
            "title": "Straßenbahn",
            "name": "tram",
            "icon_url": "https://www.dvb.de/assets/img/trans-icon/transport-tram.svg"
        },
        "diva": {
            "number": 11008,
            "network": "voe"
        }
    },
    {
        "line": "1",
        "direction": "Bf. Mitte",
        "platform": {
            "name": "2",
            "type": "Platform"
        },
        "arrivalTime": "2017-02-17T22:24:50.000Z",
        "arrivalTimeRelative": 3,
        "scheduledTime": "2017-02-17T22:23:00.000Z",
        "scheduledTimeRelative": 1,
        "delayTime": 2,
        "state": "Delayed",
        "mode": {
            "title": "Straßenbahn",
            "name": "tram",
            "icon_url": "https://www.dvb.de/assets/img/trans-icon/transport-tram.svg"
        },
        "diva": {
            "number": 11001,
            "network": "voe"
        }
    }
]

Find stops by name

Search for a single stop in the network of the DVB. Returns an array of all possible hits including their GPS coordinates.

Example:

dvb.find('zellesch', function(err, data){
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

Output:

[{
    "stop":"Zellescher Weg",
    "id":"33000312",
    "coords":[51.028365791,13.74584705]
}]

Find POIs with coordinates

Search for different kinds of POIs inside a given square.

// southwest point
var swlat = 51.04120;
var swlng = 13.70106;

// northeast point
var nelat = 51.04615;
var nelng = 13.71368;

var pinType = dvb.pins.type.STOP; // type of the Pins

dvb.pins(swlat, swlng, nelat, nelng, pinType, function (err, data) {
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

Output:

[
    {
        "id": "33000143",
        "name": "Saxoniastraße",
        "coords": [
            51.043733606562675,
            13.706279792263878
        ],
        "connections": [
            {
                "line": "7",
                "type": "1"
            },
            {
                "line": "8",
                "type": "1"
            },
            {...}
        ]
    },
    {...}
]

The default pin type is STOP, other posible types are:

pins.type = {
    STOP: 'stop',
    PLATFORM: 'platform',
    POI: 'poi',
    RENT_A_BIKE: 'rentabike',
    TICKET_MACHINE: 'ticketmachine',
    CAR_SHARING: 'carsharing',
    PARK_AND_RIDE: 'parkandride'
};

Look up coordinates for POI

Find the coordinates for a given POI id.

Example:

var id = 33000143;

dvb.coords(id, function (err, data) {
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

Output:

[
    51.043733606562675,
    13.706279792263878
]

Address for coordinates

Look up the address for a given coordinate.

Example:

var lat = 51.04373;
var lng = 13.70320;

dvb.address(lat, lng, function (err, data) {
    if (err) throw err;
    console.log(JSON.stringify(data, null, 4));
});

Output:

{
    "city": "Dresden",
    "address": "Kesselsdorfer Straße 1"
}

Misc

By the way, stop names in queries are very forgiving. Better use the ID of the stop. As long as the server sees it as an unique hit, it'll work. 'Helmholtzstraße' finds the same data as 'helmholtzstrasse', 'Nürnberger Platz' as 'nuernbergerplatz' etc.

One last note, be sure to use EDUROAM=TRUE as environment variable from inside the network of the TU Dresden.