Giter Site home page Giter Site logo

mvg-node's Introduction

mvg-node

NodeJS client for the Munich Public Transport System

Install

$ npm install mvg-node

Usage

Getting departures

const mvg = require('mvg-node');

(async () => {
  let home = await mvg.getStation('Feldbergstr')

  let departures = await mvg.getDepartures(home);
  console.log(departures);
})();
Output
[ { departureTime: 1500923983000,
    product: 'b',
    label: '194',
    destination: 'Trudering Bf.',
    live: true,
    lineBackgroundColor: '#0d5c70',
    departureId: 325930522,
    sev: false,
    time: 2017-07-24T19:19:43.000Z },
  { departureTime: 1500924014000,
    product: 'b',
    label: '192',
    destination: 'Neuperlach Zentrum',
    live: true,
    lineBackgroundColor: '#0d5c70',
    departureId: -120781808,
    sev: false,
    time: 2017-07-24T19:20:14.000Z },
    ... ]

API

async getStation(input) -> object

Fetch information about a specific station

Parameter Description
input Either a Number (station ID) or a String (station name)
Returns An Object containing information about a specific station. This object can be passed to the other functions

async getStations(input) -> array

Search stations by name

Parameter Description
name The station name to search for
Returns An Array of object representing stations

async allStations() -> array

Fetch all stations

async getDepartures(station) -> array

Load a specific station's upcoming departures

Parameter Description
station Either a station object or a station id
Returns An Array of upcoming departures from that station

async getRoute(start, destination, options) -> array

Get routes between two stations

Parameter Description
start The route's starting point (either a station object, or a station id (Number) or a station name (String)
destination The route's destination (either a station object, or a station id (Number) or a station name (String)
options Either a date object (the route's starting time) or some more options (start, arrival, maxTravelTimeFootwayToStation, maxTravelTimeFootwayToDestination)
Returns An Array of routes between the two stations

CLI

$ npm install --global mvg-node
Usage
$ mvg-node --help

  NodeJS client for the Munich Public Transport System

  Usage
    $ mvg-node [input] <options>

  Commands
     station      Get information about a specific station
     departures   Get upcoming departures for a specific station.

  Options
     --all        By default, this shows the next 10 departures. Pass `--all` to get all upcoming departures


  Examples
    $ mvg-node station 953

    $ mvg-node departures 'Hauptbahnhof'

Get departures

$ mvg-node departures 'Hauptbahnhof'
Upcoming departures for 'Hauptbahnhof':
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   ⏳    β”‚                                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1 min   β”‚ S8 Herrsching                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1 min   β”‚ U5 Neuperlach SΓΌd                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1 min   β”‚ U1 Olympia - Einkaufszentrum           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1 min   β”‚ U1 Mangfallplatz                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2 min   β”‚ U5 Laimer Platz                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 2 min   β”‚ Bus 58 Silberhornstraße                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 3 min   β”‚ S7 HΓΆhenkirchen-Siegertsbrunn          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 4 min   β”‚ U2 Feldmoching                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 4 min   β”‚ Tram 16 Romanplatz                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 4 min   β”‚ U2 Messestadt Ost                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

License

MIT Β© Lukas Kollmer

mvg-node was inspired by leftshift/python_mvg_api

mvg-node's People

Contributors

henrik-muehe avatar lostdesign avatar lukaskollmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mvg-node's Issues

Find a new API

they seem to have shut down the API used here, find a replacement and use that instead

Unexpected token < in JSON at position 0 -> mvg.getRoute()

Hi,

i am using mvg.getRoute() sometimes it's working fine and sometimes it's throwing Uncaught SyntaxError: Unexpected token < in JSON at position 0. The stations i tried were Hauptbahnhof -> Ostbahnhof.

// vue component
async getRoutesOut(){
  let routesOut = 
    await mvg.getRoute(this.route.from, this.route.to)
    .then(res =>{ 
        this.routesOut = res;
    })
    .catch(err => console.log(err));
},
VM553:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (C:\Users\user\Documents\code\mvg\node_modules\mvg-node\index.js:16)
    at Request.self.callback (C:\Users\user\Documents\code\mvg\node_modules\request\request.js:185)
    at Request.emit (events.js:194)
    at Request.<anonymous> (C:\Users\user\Documents\code\mvg\node_modules\request\request.js:1161)
    at Request.emit (events.js:194)
    at IncomingMessage.<anonymous> (C:\Users\user\Documents\code\mvg\node_modules\request\request.js:1083)
    at Object.onceWrapper (events.js:282)
    at IncomingMessage.emit (events.js:199)
    at endReadableNT (_stream_readable.js:1141)

resolve(JSON.parse(body));

It seems like it's due to MVG having issues, so maybe there might be a need to catch their error message:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Language" content="de">
  <title>apps.mvg-fahrinfo.de - Error 500, internal error - ooops</title>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="de">
</head>
<body style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<font> </font>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table style="border-collapse: collapse;" id="AutoNumber1" border="0"
 bordercolor="#111111" cellpadding="0" cellspacing="0" width="100%">
  <tbody>
    <tr>
      <td width="30%"> <br>
      </td>
      <td width="70%"><font face="Arial">
      <h2> 500 - interner Fehler</h2>
      <p>Leider ist bei der Verarbeitung Ihrer Anfrage ein interner
Fehler aufgetreten.<br>
Bitte versuchen Sie den Zugriff in einigen Minuten erneut.<br>
      </p>
      <p>Wir entschuldigen uns f&uuml;r evtl. auftretende
Unannehmlichkeiten und<br>
bitten um Ihr Verst&auml;ndnis.<br>
      </p>
      <p allign="center">&nbsp;</p>
      </font>
      <p>&nbsp; </p>
      </td>
    </tr>
  </tbody>
</table>
</body>
</html>

License

Hey, cool project!
However, it seems to be at least partially based on code from https://github.com/leftshift/python_mvg_api (indicated by similarities in the code and the fact you forked it a day before publishing this).
My project is also licensed under the MIT license, so what you did is totally fine (and encouraged! Thanks!) as long as you include the original copyright notice (=my name).
It'd be great if you could do that, thanks!

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.