Skip to main content

A CLI tool to get quick access to live MVG data from the command line.

Project description

MVG-cli

A CLI tool for easy access to live MVG (Munich public transport) data from the command line. A screenshot of the Terminal where the mvg command is run

Why?

When I want to catch the train to go to university or to the city, I need to check the upcoming departures with live delay data of the Munich metro at my local metro station. Using the MVG app or website is a bit cumbersome for this use case.

Obviously, the only sensible solution is to create a CLI tool that makes it super convenient to get live data about upcoming departures right from the Terminal. And well, here we are.

Usage

The basic idea is that you can define your favorite routes (start and destination stations) and then get the current departures by just typing mvg (just like in the screenshot at the top). In addition to managing your favorites, the CLI also allows manual querying.

Manual Querying

You can do manual queries for upcoming departures from a given metro station in the MVG system. The basic syntax in this case is:

mvg -f <start station> [-t <destination station>] [-o <offset>] [-l <limit>]

The -f / --from parameter ('from') is required. Specify the starting train station which you're interested in, e.g., 'Marienplatz'. Optionally, you can also supply:

  • -t / --to: filter the departures by their final destination station (simple string matching)
  • -o / --offset: offset the departures by a number of minutes (e.g., in how many minutes you will be at the station)
  • -l / --limit: limit the number of results (5 by default)

For example, to query upto 7 departures from 'Marienplatz' having 'Garching' in their name and leaving in at least 5min, you would use

mvg -f Marienplatz -t Garching -o 5 -l 7

Favorites

If you just run mvg, your favorite queries will be executed and displayed. A favorite query has just the same properties as a manual query (described above). To manage your favorites, use these commands:

Listing your favorites

mvg favorites list

Adding a favorite

mvg favorites add -f <start station> [-t <destination station>] [-o <offset>] [-l <limit>]

Using the same parameters as the manual query method described above.

Removing a favorite

mvg favorites remove -i <index>

When listing your favorites, each entry will have a 0-based index. Specify this index of the favorite you want to remove.

Defaults

Currently, only one configuration setting is available: in order to get colored departure results (green if you will catch it easily, orange if it's going to be close and red if it's probably not going to be enough), you need to define how many minutes it will approximately take you to the station. For example, if it takes you about 5min, run:

mvg defaults time-to-station 5

Subsequent manual and favorite queries will be colorized accordingly.

Important Legal Note

The CLI uses the mvg_api library, which in turn queries the MVG JSON API. This only allows private, non-commercial and moderate use. Do not use it for data mining. I'm not a lawyer and this is not legal advice. Please check the official terms of service.

Upcoming Features

  • use the MVG JSON API directly to allow for better pagination and station selection
  • add more sophisticated routing features (i.e., not just start and destination station but arbitrary stations in the metro system)
  • document the code better

Acknowledgements

Among other dependencies, this project is mainly based on the mvg_api library by leftshift to query the MVG API.

Contributing

The CLI is structued in an extensible manner by design, as I think a lot of very useful features could be added in the future (see 'Upcoming Features' above). I'm very happy to accept contributions!

The code is currently not documented very well since it was hacked together in a few hours, so if you need some pointers or want to discuss your idea, feel free to reach out! You'll find my contact info on my website.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mvg-cli-1.0.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

mvg_cli-1.0.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file mvg-cli-1.0.0.tar.gz.

File metadata

  • Download URL: mvg-cli-1.0.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for mvg-cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c5188240647bc11386da3d6405b6ada8e4dd632df2eea1b03e1da1a22cc86543
MD5 214ed5ff6fa0bddc603bd0084b3521b6
BLAKE2b-256 360526de12f13e5de0d7fb027f34eca114ac4dee6d3dfeda378fa02e14a5da11

See more details on using hashes here.

File details

Details for the file mvg_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mvg_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for mvg_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ed8e56f4821c8da68dad74046ffe8c70f7d802bd8c60196c50a4ff93aa034d
MD5 ccc22feec9c737b893340a0f965a717f
BLAKE2b-256 62497d659f0b36a543a9f84286e933cffdd6ce8e0575401b4ecf721ebb10d491

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page