https://github.com/lukaskollmer/mvg-node
ππ NodeJS client for the Munich Public Transport System
https://github.com/lukaskollmer/mvg-node
munich nodejs public-transport
Last synced: over 1 year ago
JSON representation
ππ NodeJS client for the Munich Public Transport System
- Host: GitHub
- URL: https://github.com/lukaskollmer/mvg-node
- Owner: lukaskollmer
- License: mit
- Created: 2017-07-23T15:26:29.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T02:49:33.000Z (over 3 years ago)
- Last Synced: 2024-04-15T08:10:43.930Z (about 2 years ago)
- Topics: munich, nodejs, public-transport
- Language: JavaScript
- Homepage:
- Size: 112 KB
- Stars: 10
- Watchers: 3
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# mvg-node
> NodeJS client for the Munich Public Transport System
## Install
```
$ npm install mvg-node
```
## Usage
### Getting departures
```js
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]
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
```bash
$ 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](https://lukaskollmer.me)
`mvg-node` was inspired by [leftshift/python_mvg_api](https://github.com/leftshift/python_mvg_api)