Skip to main content

Displays upcoming departure times from stations on the Stuttgart public transport network

Project description

vvs is a set of tools for displaying upcoming departure times of buses, trains and trams from stations in the Verkehrsverbund Stuttgart.

Having started a new job, I was unfamiliar with the tram timetable for getting home, and wanted a simple way of seeing, at a glance, how much time I have until the next tram leaves for home.

I spend most of my working day staring at a computer terminal, always in a tmux session, so that seemed like a good fit:

screenshot.png

In the screenshot above, you can see that there are two trams leaving very shortly, after which the next one is in a half an hour. So, it’s easy to quickly decide whether it’s worth it to jump up and rush out the door, without having to waste time opening up the VVS website.

What it isn’t

vvs isn’t a console client for the VVS website. It won’t allow you to check routes and connections between two stops, for example (although this could be implemented with relatively little difficulty).

Getting Started

Installation

Install using pip3:

pip3 install vvs

It goes without saying that you should install into a virtualenv.

Finding your station ID

Have a look in the stations.json file for the station that you want to monitor. Every station is paired with an ID, and you’ll need this when running vvs.

Please note that the stations.json file in this repo won’t be kept updated. If you can’t find your station ID, follow the instructions here.

Setting up the scraper

Now we’ve got our station ID, we’ll want to scrape data for that station. This can be achieved by using the vvs scrape command. We’ll then want to cache this data somewhere locally. So, if our station ID were 5007115 (Hulb), we’d set up a cronjob to do this every few minutes:

*/3 * * * * vvs scrape 5007115 > ~/.vvs.json

With this command, we’ll be tracking the departures of all public transport from Hulb - but in both directions. We just want departures heading in to town.

In order to filter for what we want, we first use the list_directions subcommand:

$ vvs list_directions 5007115
Herrenberg
Kirchheim (T)
Neckarpark
Plochingen
$

This is a list of all terminating stations for public transport passing through Hulb. Departures of the S-Bahn in the direction of Kirchheim an der Teck and Plochingen are the ones we’re after, so we’ll filter for them:

*/3 * * * * vvs scrape 5007115 --direction Plochingen --direction 'Kirchheim (T)' > ~/.vvs.json

Now we should be getting the data we’re after!

Displaying the data

The vvs display command is used to display the data we’ve saved. The style in which it displays the data can be customized:

$ vvs display ~/.vvs.json
In 7, 22, 37 min
$
$ vvs display --limit 10 ~/.vvs.json
In 6, 21, 36, 51, 66, 81, 96, 114, 144, 174 min
$
$ vvs display --limit 10 --format %H:%M ~/.vvs.json
19:25, 19:40, 19:55, 20:10, 20:25, 20:40, 20:55, 21:13, 21:43, 22:13
$

Python’s time formatting directives (link) are used for string formatting.

Troubleshooting

Locales

If you get an error that looks like this:

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.

Make sure you have your locales set correctly (LC_ALL and LANG are exported). If that’s not possible, then set them temporarily when you invoke vvs, e.g.:

LC_ALL=en_US.utf-8 LANG=en_US.utf-8 vvs scrape 5007115

Contact

Aengus Walton ventolin@gmail.com

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

vvs-0.4.6.tar.gz (103.9 kB view details)

Uploaded Source

Built Distribution

vvs-0.4.6-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file vvs-0.4.6.tar.gz.

File metadata

  • Download URL: vvs-0.4.6.tar.gz
  • Upload date:
  • Size: 103.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vvs-0.4.6.tar.gz
Algorithm Hash digest
SHA256 81ceddc0f816b7108fe024f51d2b1ad17ab9090c176dd201a5c19c206398c1ee
MD5 7108bf208bb02745d3e3353bee973d4b
BLAKE2b-256 62068c1641fdbe89789da9b3c7dbff734187a523cdf0947c88f07381b37d401b

See more details on using hashes here.

File details

Details for the file vvs-0.4.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for vvs-0.4.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b83e40a91ee1408b2cd5a6a3c339ac5f9260f7b04b447e51742dd50e668d531
MD5 8c625b4f5c0f012c0047925c33d381dc
BLAKE2b-256 2e76cdcfe08892da72d5b3f1b1d98ddb800dd5cf2a6952704965ccbcd3abef09

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