How to display departures for MVG stations in Emacs

Posted on November 16, 2018
Tags: howto, emacs

Simple function in Emacs Lisp to display departures for stations in the Munich public transport system.

I am currently in Berkeley. Fortunately, there is a public transportation system, namely the Bay Area Rapid Transit (BART), and I found a nice emacs package to query departure times. The package is called bart-mode and can easily be setup by

(use-package bart-mode
  :config
  (setq bart-station 'dbrk))

M-x bart then shows you the next departures from the station “Downtown Berkeley” abbreviated by dbrk in the custom variable bart-stations.

I thought this is neat and I would like to have the same functionality for the public transport system in my hometown Munich.

Find the code below.

My elisp-fu is not that good, but the following function got the job done. It’s just a simple ivy-selection for the station name and eww browsing to a sort of hidden api that I found here.

The M-x mvg/departure allows to select a station and then opens up a eww window showing all depatures.

(defconst mvg/stations '("Aidenbachstraße"
                         "Allach"
                         "Alte Heide"
                         "Altenerding"
                         "Am Hart"
                         "Am Münchner Tor"
                         "Amalienburgstraße"
                         "Anni-Albers-Straße"
                         "Arabellapark"
                         "Arabellapark/Klinikum Bogenhausen"
                         "Arnbach"
                         "Aubing"
                         "Aufhausen"
                         "Aying"
                         "Bachern–Dachau Stadt"
                         "Baierbrunn"
                         "Baldham"
                         "Basler Straße"
                         "Berg am Laim Bahnhof"
                         "Berg am Laim"
                         "Bonner Platz"
                         "Brudermühlstraße"
                         "Buchenau"
                         "Buchenhain"
                         "Böhmerwaldplatz"
                         "Candidplatz"
                         "Dachau Bahnhof"
                         "Daglfing"
                         "Deisenhofen"
                         "Derbolfinger Platz"
                         "Dietlindenstraße"
                         "Domagkstraße"
                         "Donnersbergerbrücke"
                         "Donnersbergerstraße"
                         "Dülferstraße"
                         "Dürrnhaar"
                         "Ebenhausen-Schäftlarn"
                         "Ebersberg"
                         "Eching"
                         "Effnerplatz"
                         "Eglharting"
                         "Eichenau"
                         "Englschalking"
                         "Erding"
                         "Erding-Fliegerhorst"
                         "Erdweg"
                         "Esting"
                         "Fasanenpark"
                         "Fasanerie"
                         "Fasangarten"
                         "Feldafing"
                         "Feldkirchen"
                         "Feldmoching"
                         "Feldmoching†"
                         "Flughafen Besucherpark"
                         "Flughafen München"
                         "Forstenrieder Allee"
                         "Frankfurter Ring"
                         "Fraunhoferstraße"
                         "Freiham"
                         "Freimann"
                         "Freising"
                         "Friedenheimer Straße"
                         "Fröttmaning"
                         "Furth"
                         "Fürstenfeldbruck"
                         "Fürstenried West†"
                         "Fürstenrieder Straße"
                         "Garching"
                         "Garching-Forschungszentrum†"
                         "Garching-Hochbrück"
                         "Gasteig"
                         "Gauting"
                         "Geisenbrunn"
                         "Geltendorf"
                         "Gelting"
                         "Georg-Brauchle-Ring"
                         "Geretsried Mitte"
                         "Geretsried Süd"
                         "Germering-Unterpfaffenhofen"
                         "Gern"
                         "Gernlinden"
                         "Giesing Bahnhof"
                         "Giesing Bhf."
                         "Giesing"
                         "Gilching-Argelsried"
                         "Giselastraße"
                         "Goetheplatz"
                         "Gondrellplatz"
                         "Grafing Bahnhof"
                         "Grafing Stadt"
                         "Grafrath"
                         "Gronsdorf"
                         "Großhadern"
                         "Großhelfendorf"
                         "Großhesselohe Isartalbahnhof"
                         "Großhesseloher Brücke"
                         "Grub"
                         "Gräfelfing"
                         "Gröbenzell"
                         "Grünwald"
                         "Haar"
                         "Hackerbrücke"
                         "Haderner Stern"
                         "Hallbergmoos"
                         "Harras"
                         "Harthaus"
                         "Harthof"
                         "Hauptbahnhof Nord"
                         "Hauptbahnhof Süd"
                         "Hauptbahnhof"
                         "Hebertshausen (Altomünster)"
                         "Heimeranplatz"
                         "Heimstetten"
                         "Herrsching"
                         "Hirschgarten"
                         "Hochschule München"
                         "Hohenbrunn"
                         "Hohenschäftlarn"
                         "Hohenzollernplatz"
                         "Holzapfelkreuth"
                         "Holzkirchen"
                         "Höhenkirchen-Siegertsbrunn"
                         "Höllriegelskreuth"
                         "Icking"
                         "Implerstraße"
                         "Innsbrucker Ring"
                         "Isartor"
                         "Ismaning"
                         "Johanneskirchen"
                         "Josephsburg"
                         "Josephsplatz"
                         "Karl-Preis-Platz"
                         "Karlsfeld"
                         "Karlsplatz (Stachus) Nord"
                         "Karlsplatz (Stachus)"
                         "Karlsplatz-Stachus"
                         "Karolinenplatz"
                         "Kieferngarten"
                         "Kirchseeon"
                         "Kleinberghofen"
                         "Klinikum Bogenhausen"
                         "Klinikum Großhadern"
                         "Kolumbusplatz"
                         "Kreillerstraße"
                         "Kreuzstraße"
                         "Kurfürstenplatz"
                         "Königsplatz"
                         "Laim"
                         "Laimer Platz"
                         "Langwied"
                         "Lautensackstraße"
                         "Lehel"
                         "Leienfelsstraße"
                         "Leonrodplatz"
                         "Leuchtenbergring"
                         "Lochham"
                         "Lochhausen"
                         "Lohhof"
                         "Machtlfinger Straße"
                         "Maillingerstraße"
                         "Maisach"
                         "Malching"
                         "Mammendorf"
                         "Mangfallplatz"
                         "Mariahilfplatz"
                         "Marienplatz"
                         "Markt Indersdorf"
                         "Markt Schwaben"
                         "Max-Weber-Platz"
                         "Maximilianeum"
                         "Maxmonument"
                         "Messestadt-Ost"
                         "Messestadt-West"
                         "Michaelibad"
                         "Milbertshofen"
                         "Mittersendling"
                         "Moosach Bahnhof"
                         "Moosach"
                         "Moosacher St.-Martins-Platz"
                         "Moosach†"
                         "Moosfeld"
                         "Münchner Freiheit"
                         "Neuaubing"
                         "Neubiberg"
                         "Neufahrn"
                         "Neugilching"
                         "Neuperlach Süd"
                         "Neuperlach Süd†"
                         "Neuperlach Zentrum"
                         "Niederroth"
                         "Nordfriedhof"
                         "Obermenzing"
                         "Oberschleißheim"
                         "Obersendling"
                         "Olching"
                         "Olympia-Einkaufszentrum"
                         "Olympiazentrum"
                         "Ostbahnhof"
                         "Ostfriedhof"
                         "Ottenhofen"
                         "Otterfing"
                         "Ottobrunn"
                         "Partnachplatz"
                         "Parzivalplatz"
                         "Pasing Bahnhof"
                         "Pasing"
                         "Peiß"
                         "Perlach"
                         "Petershausen"
                         "Petuelring"
                         "Planegg"
                         "Poccistraße"
                         "Poing"
                         "Possenhofen"
                         "Potsdamer Straße"
                         "Prinzregentenplatz"
                         "Puchheim"
                         "Pullach"
                         "Pulling"
                         "Quiddestraße"
                         "Richard-Strauss-Straße"
                         "Riem"
                         "Romanplatz"
                         "Rosenheimer Platz"
                         "Rotkreuzplatz"
                         "Röhrmoos"
                         "Sauerlach"
                         "Scheidplatz"
                         "Schwabhausen"
                         "Schwabing Nord"
                         "Schwaigerloh (Wendeanlage)"
                         "Schwaigerloh"
                         "Schwanseestraße"
                         "Schwanthalerhöhe"
                         "Schöngeising"
                         "Seefeld-Hechendorf"
                         "Sendlinger Tor"
                         "Siemenswerke"
                         "Silberhornstraße"
                         "Solln"
                         "St. Emmeram"
                         "St. Koloman"
                         "St.-Martin-Straße"
                         "St.-Quirin-Platz"
                         "St.-Veit-Straße"
                         "Starnberg Nord"
                         "Starnberg"
                         "Steinebach"
                         "Stiglmaierplatz"
                         "Stockdorf"
                         "Studentenstadt"
                         "Taufkirchen"
                         "Thalkirchen"
                         "Theatinerstraße"
                         "Therese-Giehse-Allee"
                         "Theresienstraße"
                         "Theresienwiese"
                         "Trappentreustraße"
                         "Trudering"
                         "Tutzing"
                         "Türkenfeld"
                         "Universität"
                         "Unterföhring"
                         "Unterhaching"
                         "Untermenzing"
                         "Untersbergstraße"
                         "Unterschleißheim"
                         "Vaterstetten"
                         "Vierkirchen-Esterhofen"
                         "Westendstraße"
                         "Westfriedhof"
                         "Westkreuz"
                         "Westpark"
                         "Wettersteinplatz"
                         "Weßling"
                         "Willibaldplatz"
                         "Wolfratshausen"
                         "Wächterhof"
                         "Zorneding"
                         )
  "MVG Stations collected from
https://de.wikipedia.org/wiki/Stra%C3%9Fenbahn_M%C3%BCnchen
https://de.wikipedia.org/wiki/Liste_der_Stationen_der_S-Bahn_M%C3%BCnchen
https://en.wikipedia.org/wiki/List_of_Munich_U-Bahn_stations
")

(defun mvg/departure (station)
  "Look up upcomming departures for MVG station"
  (interactive (list (ivy-read "Choose MVG station: " mvg/stations)))
  (let* ((base-url "http://www.mvg-live.de/ims/dfiStaticAuswahl.svc")
         (url (concat url
                      "?haltestelle="
                      (url-hexify-string station))))
    (save-excursion
      (switch-to-buffer-other-window "*mvg*")
      (eww url)
      (kill-buffer "*mvg*"))))