qtile transport widget for Munich

After settling down in Munich I managed to adjust the qtile window manager widget I created for Zurich to the Munich public transport system.

There is neither an open data provider like in Zurich nor an official API documentation by the MVG but nevertheless, since www.mvg.de uses a beautifully responsive JavaScript FrontEnd to query connections, using FireBug one can find the following request

GET https://www.mvg.de/fahrinfo/api/routing/?fromStation=40&toStation=1260

with the following http header

which can be used to perform the queries. The results are again provided in JSON such that only small changes of the ZH version of the widget are necessary.

The full code is shown below.

Posted in Linux, Python | Tagged , | Leave a comment

Streaming without pain using mpv and youtube-dl

Watching streams in the browser is usually very annoying. In the worst case, there is only a flashplayer available which won't load because your last update of the flash plugin was already 10 minutes ago and in the meantime it was deactivated again due to newly discovered vulnerabilities. If it works, at least one of your cores will have a load close to 70%, your are bothered by layer-ads and also fast-forwarding and searching in the stream is cumbersome, unstable or not even possible using the flashplayer's controls.

A very nice alternative is to stream using a full-scale media player like mpv, which can be directly called with the command-line providing the url as parameter:

For some streaming sites the url is unfortunately in the code somewhere, such that some RegEx Script (using Greasemonkey for example) is needed. Fortunatetly, mpv also provides an interface to the python package youtube-dl  which includes link extractors for a broad range of streaming websites. A list can be found here and of course the project can be extended by writing an extractor for your favourite website yourself.

For starting the stream one just has to add the --ytdl option and the url of the streaming website



Posted in Linux | Tagged , , | Leave a comment

A public transport widget for qtile

Some time ago I, when I once again missed the tram to the campus by a couple of seconds, I found out that there is an open data initiative in Switzerland (http://transport.opendata.ch) providing a JSON API and access to very detailed public transport data.

Using the python request library it is very easy to query the next connections for your local tram or train station.  A full request, for example, looks like

GET http://transport.opendata.ch/v1/connections?from=008591256&to=008591123&direct=1&limit=2&fields[]=connections/from/departureTimestamp&fields[]=connections/from/station&fields[]=connections/to/arrivalTimestamp&fields[]=connections/to/station

which queries the next two (limit=2) direct (direct=1) connections from Zürich Leutschenbach (from=008591256) to ETH Zentrum (to=008591123). For these two connections we select departure and arrival timestamps as well as the station names (fields[]=...). The python request and selection of the data is then achieved by

such that

contains the departure station name of the first connection.

Next, I integrated the query into a widget for my window manager qtile. qtile is a tiling window manager written entirely  in python and configurable in python. It can consequently be very easily modified or extended. I will elaborate in later post on the advantages of tiling window managers in general and on qtile in particular.

qtile provides a base class ThreadedPollText for widgets that regularly need to query data from some source without blocking the window manager's main queue. The OpenTransportTicker is just derived from this class and contains some additional methods to control the onClick-behavior of the widget (namely browsing through the list of connections).


The result can be seen above, in the screenshot of the window manager's. The full code is shown below.


Posted in Linux, Python | Tagged , , , , | Leave a comment