Coder Social home page Coder Social logo

mvg-live's Introduction

MVG-LIVE

A ruby client and CLI for mvg-live.de the real-time interface for Munich's public transportation service.

Build Dependencies Downloads Tags Issues License Version

Flattr

Installation

Docker

docker pull rmoriz/mvg-live:latest
docker run -it --rm rmoriz/mvg-live Marienplatz

Rubygem

gem install mvg-live

Please use Ruby 2.2.x or greater.

Ruby

require 'mvg/live'

result = MVG::Live.fetch 'Sendlinger Tor'
=> [{:line=>"U7", :destination=>"Westfriedhof", :minutes=>0}, {:line=>"U3", :destination=>"Olympiazentrum", :minutes=>0}, {:line=>"17", :destination=>"Schwanseestraße", :minutes=>0}, {:line=>"U3", :destination=>"Fürstenried West", :minutes=>0}, {:line=>"16", :destination=>"Romanplatz", :minutes=>0}, {:line=>"27", :destination=>"Petuelring", :minutes=>0}, {:line=>"152", :destination=>"Landshuter Allee", :minutes=>1}, {:line=>"U2", :destination=>"Feldmoching", :minutes=>1}, {:line=>"18", :destination=>"Effnerplatz", :minutes=>1}, {:line=>"U1", :destination=>"Olympia-Einkaufsz.", :minutes=>2}, {:line=>"U7", :destination=>"Neuperlach Zentrum", :minutes=>2}, {:line=>"U6", :destination=>"Klinikum Großhadern", :minutes=>2}, {:line=>"U6", :destination=>"Garching-Forschungs.", :minutes=>3}, {:line=>"18", :destination=>"Gondrellplatz", :minutes=>3}, {:line=>"16", :destination=>"St. Emmeram", :minutes=>4}, {:line=>"17", :destination=>"Amalienburgstraße", :minutes=>4}, {:line=>"U3", :destination=>"Moosach", :minutes=>4}, {:line=>"U3", :destination=>"Fürstenried West", :minutes=>5}, {:line=>"U2", :destination=>"Messestadt Ost", :minutes=>5}, {:line=>"U1", :destination=>"Mangfallplatz", :minutes=>6}]

result = MVG::Live.fetch 'Sendlinger Tor', :transports => [ :tram ]
=> [{:line=>"17", :destination=>"Schwanseestraße", :minutes=>0}, {:line=>"16", :destination=>"Romanplatz", :minutes=>1}, {:line=>"27", :destination=>"Petuelring", :minutes=>1}, {:line=>"18", :destination=>"Effnerplatz", :minutes=>2}, {:line=>"18", :destination=>"Gondrellplatz", :minutes=>3}, {:line=>"16", :destination=>"St. Emmeram", :minutes=>4}, {:line=>"17", :destination=>"Amalienburgstraße", :minutes=>5}, {:line=>"16", :destination=>"Romanplatz", :minutes=>8}, {:line=>"17", :destination=>"Schwanseestraße", :minutes=>9}, {:line=>"27", :destination=>"Petuelring", :minutes=>9}, {:line=>"18", :destination=>"Effnerplatz", :minutes=>9}, {:line=>"18", :destination=>"Gondrellplatz", :minutes=>12}, {:line=>"16", :destination=>"St. Emmeram", :minutes=>13}, {:line=>"17", :destination=>"Amalienburgstraße", :minutes=>16}, {:line=>"27", :destination=>"Petuelring", :minutes=>16}, {:line=>"16", :destination=>"Romanplatz", :minutes=>17}, {:line=>"18", :destination=>"Effnerplatz", :minutes=>17}, {:line=>"17", :destination=>"Schwanseestraße", :minutes=>19}, {:line=>"18", :destination=>"Gondrellplatz", :minutes=>22}, {:line=>"16", :destination=>"St. Emmeram", :minutes=>23}]

CLI (command line interface)

This gem provides two scripts:

mvg

Returns a human readable listing of the next depatures

$ mvg Hauptbahnhof
$ mvg Marienplatz
$ mvg Moosach Bf.

example output:

================================================
Hauptbahnhof: U, Bus, Tram, S
======================================[ 09:03 ]=
19  | Pasing                        |  0 Minuten
16  | Romanplatz                    |  1 Minuten
U2  | Feldmoching                   |  1 Minuten
U1  | Mangfallplatz                 |  1 Minuten
S8  | Herrsching                    |  2 Minuten
U2  | Messestadt Ost                |  3 Minuten
17  | Schwanseestraße               |  3 Minuten
S7  | Aying                         |  4 Minuten
U4  | Arabellapark                  |  4 Minuten
U4  | Theresienwiese                |  5 Minuten
S6  | Ostbahnhof                    |  5 Minuten
U2  | Messestadt Ost                |  6 Minuten
S2  | Petershausen                  |  6 Minuten
20  | Moosach Bf.                   |  6 Minuten
U1  | Olympia - Einkaufszentrum     |  6 Minuten
19  | Pasing                        |  8 Minuten
U5  | Neuperlach Süd                |  8 Minuten
16  | Romanplatz                    |  8 Minuten
U5  | Laimer Platz                  |  9 Minuten
U1  | Mangfallplatz                 | 11 Minuten

displays alternates/suggestions in case of unclear/invalid station name:

$ mvg Tor
================================================
   /!\ Station unknown!  Did you mean...? /!\   
================================================
 - Am Münchner Tor
 - Sendlinger Tor

mvg_json

Returns JSON

$ mvg_json Hauptbahnhof
$ mvg_json Marienplatz
$ mvg_json Moosach Bf.

User Preferences

You can specify a default station or a default transports list (e.g. only specific transport systems) in a JSON file. This only affects the CLI version! The first available file will be loaded:

  1. file specified in the environment variable: MVG_FILE
  2. an existing .mvg file in the current directory (PWD)
  3. an existing .mvg file in the home directory of the current user (HOME)

Example .mvg file:

 {"default_transports":["u"],"default_station":"Hauptbahnhof"}

This limits the transports to U-Bahn and uses "Hauptbahnhof" as default station:

$ mvg
=[                         /Users/rmoriz/.mvg ]=
Hauptbahnhof: U
======================================[ 13:34 ]=
U1  | Mangfallplatz                 |  0 Minuten
U2  | Feldmoching                   |  0 Minuten
U4  | Arabellapark                  |  3 Minuten
U4  | Theresienwiese                |  4 Minuten
...

You can overwrite the station as mentioned above but the transport limitation is currently global!

$ mvg Ostbahnhof
=[                         /Users/rmoriz/.mvg ]=
Ostbahnhof: U
======================================[ 13:37 ]=
U5  | Neuperlach Süd                |  2 Minuten
U5  | Laimer Platz                  |  8 Minuten
U5  | Neuperlach Süd                | 12 Minuten
...

The default transports list (= all available) is:

Ruby:

[ :u, :bus, :tram, :s ]

JSON:

["u", "bus", "tram", "s"]

Minitest-Specs

see "specs/"-directory

Disclaimer

This project is not related, acknowledged, sponsored... by MVG or SWM. Use at your own risk.

License

see LICENSE file (MIT)

Copyright

Copyright

Copyright © 2016 Roland Moriz, Moriz GmbH

LinkedIn Twitter

mvg-live's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvg-live's Issues

S-Bahn Halterstellen außerhalb München funktionieren nicht

Funktionieren lediglich die Stationen im Landkreis München?
Ich würde gern die Abfahrtszeiten von Zorneding, Eglharting, Starnberg nutzen. Allerdings ist die "nächste" Station die wieder funktioniert erst "Haar" welches im Landkreis München ist. Den Rest findet es nicht.

Außerdem hätte ich noch eine Frage:
Werden Verspätungen auch mit einberechnet?

station_unknown für Maillingerstraße

Betrifft:

  • ruby version
  • cli (mvg)
  • cli (mvg_json)

Details:
Wenn ich die Maillingerstraße als station verwende, bekomme ich folgende Rückgabe

mvg_json Maillingerstraße
{"station":"Maillingerstraße","server_time":"","transports":["u","bus","tram","s"],"using_config_file":null,"result_sorted":null,"result_display":null,"station_unknown":true,"station_alternates":[]}

mvg Maillingerstraße
/!\ Station unknown! Did you mean...? /!\

bei unvöllständigem Namen alledings einen Vorschlag:

mvg Maillingerstraß
/!\ Station unknown! Did you mean...? /!\

  • Maillingerstraße

Mein keyboard ist auf de_DE.UTF-8
Ich hab andere Straßennamen mit "ß" ausprobiert.. Funzt ohne Probleme!

Kannst du das Phänomen mit der Maillingerstraße bei dir reproduzieren?

feature request: multiple (transport) defaults (~/.mvg)

Hab mehrere Öffis um die Ecke, von demher wärs cool der CLI version sagen zu können, welche ich jetzt gern hätte.
Der Aufruf könnte dann so aussehen: mvg s (für sbahn-default), oder mvg u (für ubahn-default)
Parameter als string oder symbol. Symbol wär evtl gschickter, um die alternates-sache bei string.length.eql?(1) zu behalten.

~/.mvg könnte dann so aussehen:

{"0"=>{"default_transport"=>"u", "default_station"=>"Rotkreuzplatz"}, "1"=>{"s"=>"Hauptbahnhof"}}

oder

{"u": "Rotkreuzplatz", "s": "Hauptbahnhof"}

Alternativ als parameter für MVG::Live.new /CLI erlauben
mvg "Hauptbahnhof", :transports => ["s"]
dann wäre ein alias mvgs='mvg "Hauptbahnhof", :transports => ["s"]' denkbar

:D

Installation on OS X

Servus,

Cooles Projekt! Hab gerade versucht, das Script auf meinem Mac mit OS X 10.11.3 El Capitan zu installieren. Leider schlägt die Installation fehl, vermutlich weil man seit 10.11 aus Sicherheitsgründen unter /usr/bin auch als root keine Schreibrechte mehr hat:

# gem install mvg-live
Fetching: multipart-post-1.2.0.gem (100%)
Successfully installed multipart-post-1.2.0
Fetching: faraday-0.8.11.gem (100%)
Successfully installed faraday-0.8.11
Fetching: builder-3.0.4.gem (100%)
Successfully installed builder-3.0.4
Fetching: activesupport-3.2.22.2.gem (100%)
Successfully installed activesupport-3.2.22.2
Fetching: activemodel-3.2.22.2.gem (100%)
Successfully installed activemodel-3.2.22.2
Fetching: mvg-live-1.0.1.gem (100%)
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/mvg

Mangels irgendwelcher Ruby-Kenntnisse weiß ich jetzt nicht, was nach dem fehlschlagenden Installationsschritt noch ausgeführt würde. Mit ein paar Anpassungen kann ich mvg nun aber trotzdem ausführen:

--- a/Users/manfred/mvg
+++ b/bin/mvg
@@ -1,7 +1,7 @@
 #!/usr/bin/env ruby

 require 'rubygems'
-require 'mvg/live'
+require_relative '../lib/mvg/live'

 puts MVG::Live.fetch_to_display ARGV.join(" "), { :load_user_defaults => true, :cli => true }
--- a/Users/manfred/mvg_json
+++ b/bin/mvg_json
@@ -1,7 +1,7 @@
 #!/usr/bin/env ruby

 require 'rubygems'
-require 'mvg/live'
+require_relative '../lib/mvg/live'

 puts MVG::Live.fetch_to_json ARGV.join(" "), { :load_user_defaults => true, :cli => true }
--- a/Users/manfred/live.rb
+++ b/lib/mvg/live.rb
@@ -1,10 +1,10 @@
 # encoding: UTF-8
 require 'active_model'
-require 'mvg/live/version'
-require 'mvg/live/encoding'
-require 'mvg/live/http'
-require 'mvg/live/parser'
-require 'mvg/live/cli'
+require_relative 'live/version'
+require_relative 'live/encoding'
+require_relative 'live/http'
+require_relative 'live/parser'
+require_relative 'live/cli'

 module MVG
   class Live

Vielleicht hilft das ja noch jemandem :)

Unable to install mvg-live

Any help with this? Ruby 2.3.0 is installed.

root@tb~# gem install mvg-live
Building native extensions. This could take a while...
ERROR: Error installing mvg-live:
ERROR: Failed to build gem native extension.

current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.3/ext/nokogiri

/usr/bin/ruby2.3 -r ./siteconf20180620-5854-vgyagb.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/nokogiri-1.8.3 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/arm-linux/2.3.0/nokogiri-1.8.3/gem_make.out

Linie unvollständig

Erstmal merci für dieses coole gem!! Ist auf jeden Fall praktischer als über die Webseite zu gehn! ;)

Mir ist beim ausprobieren grad ne Kleinigkeit aufgefallen. Kann dir dazu leider nur wenig infos geben - weil ich nicht schnell genug war, um mir die Ausgabe vom mvv online anzusehen. Also k.a. ob die das so übergeben haben, oder beim parsen was verloren ging:

require 'mvg/live'
result = MVG::Live.fetch 'Sendlinger Tor'

...
{:line=>"U", :destination=>"Brudermühlstraße", :minutes=>4},
...

Wird vermutlich eine U6 gewesen sein, die nur bis Brudermühlstraße gefahren ist. Werd versuchen das mal im Auge zu behalten.

Greez

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.