Skip to content

Commit

Permalink
MVG_Live:
Browse files Browse the repository at this point in the history
updated to new Pypi library "mvg", as MVG_Live is not maintained anymore.
  • Loading branch information
psilo909 committed Dec 31, 2023
1 parent 98a9257 commit 881a4c8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
50 changes: 32 additions & 18 deletions mvg_live/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
This plugin requires lib PyMVGLive. You can install this lib with:

```
sudo pip3 install PyMVGLive --upgrade
sudo pip3 install mvg --upgrade
```

This plugin provides functionality to query the data of www.mvg-live.de via the python package PyMVGLive.
This plugin provides functionality to query the data of www.mvv-muenchen.de via the python package "mvg" (pip install mvg).

Take care to not run it too often. My example below is manually triggered by a select action in the
smartVISU 2.9 select widget or a refresh button.
smartVISU 2.9 select widget including a refresh button.

Forum thread to the plugin: https://knx-user-forum.de/forum/supportforen/smarthome-py/1108867-neues-plugin-mvg_live

Expand Down Expand Up @@ -66,27 +67,40 @@ MVGWatch:
### mvg.py
For the images I am using https://commons.wikimedia.org/wiki/M%C3%BCnchen_U-Bahn?uselang=de and https://commons.wikimedia.org/wiki/Category:Line_numbers_of_Munich_S-Bahn
and put them in the dropins folder of smartVISU (/dropins/icons/myglive/Muenchen_%s.svg.png). %s is e.g. S8 or U3 and inputted from the departure array.
```html
results = sh.mvg_live.get_station_departures(sh.travel_info.mvg_station.search(), entries=15, bus=False, tram=False)
import logging
from datetime import datetime
from lib.shtime import Shtime
logger = logging.getLogger('mvg_info logics')
now = Shtime.get_instance().now()

results = sh.mvg_live.get_station_departures(sh.general.travel_info.mvg_station.search())
logger.error(results)
html_string = '<table>'
i = 1
for result in results:

dir_info = ''
line_string = '<tr><td style="width: 10px;"></td>'
line_string += '<td><img src="%s" alt="%s"/><td><td style="margin-left: 5px;"><img src="%s" alt="%s"/></td>' % (
result['productsymbolurl'], result['product'], result['linesymbolurl'], result['linename'])
line_string += '<td style="text-align: left; padding-left: 15px; width: 100%;">'
line_string += '%s </td>' % result['destination']
line_string += '<td style="color: #000; font-weight: bold; font-size: 25px;">'
line_string += '<div style="background-color: #fff; width: 30px; ">%i</div></td></tr>' % result['time']
html_string += line_string
i = i + 1
if i == 7:
break
for result in results:
if result['type'] in ["U-Bahn","S-Bahn"]:
result['linesymbolurl'] = 'https://<sv_dyndns_url>/smartVISU/dropins/icons/mvglive/Muenchen_%s.svg.png'%result['line']
dir_info = ''
line_string = '<tr><td style="width: 10px;"></td>'
line_string += '<td><img src="%s" alt="%s"/></td>' % (result['linesymbolurl'],result['linesymbolurl']) #<td><td style="margin-left: 5px;"><img src="%s" alt="%s"/>
line_string += '<td style="text-align: left; padding-left: 15px; width:60%;">'
line_string += '%s </td>' % result['destination']
line_string += '<td style="color: #000; font-weight: bold; font-size: 25px;">'
calculated_delay = ""
if int(datetime.fromtimestamp(result['time']-result['planned']).strftime("%M")) > 0:
calculated_delay = "(+%i)"%int(datetime.fromtimestamp(result['time']-result['planned']).strftime("%M"))
line_string += '<div style="background-color: #fff; width: 120px; ">%s %s</div></td></tr>' % (datetime.fromtimestamp(result['time']).strftime("%H:%M"),calculated_delay) #calculated_delay)
html_string += line_string
i = i + 1
if i == 7:
break

html_string += '</table>'
sh.travel_info.mvg_station.search.result(html_string)
sh.general.travel_info.mvg_station.search.result(html_string)
```

### smartVISU integration (Requires smartVISU 2.9, as select widget is used)
Expand Down
20 changes: 14 additions & 6 deletions mvg_live/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,34 @@
#########################################################################

import logging
import MVGLive

from mvg import MvgApi
from lib.model.smartplugin import SmartPlugin

class MVG_Live(SmartPlugin):
ALLOW_MULTIINSTANCE = False
PLUGIN_VERSION = "1.5.1"
PLUGIN_VERSION = "1.6.0"

def __init__(self, sh, *args, **kwargs):
"""
Initializes the plugin
"""
self.logger = logging.getLogger(__name__)
self._mvg_live = MVGLive.MVGLive()

def run(self):
self.alive = True

def stop(self):
self.alive = False

def get_station_departures(self, station, timeoffset=0, entries=10, ubahn=True, tram=True, bus=True, sbahn=True):
return self._mvg_live.getlivedata(station, timeoffset, entries, ubahn, tram, bus, sbahn)
def get_station(self, station):
mvg_station = MvgApi.station(station)
if mvg_station:
return mvg_station

def get_station_departures(self, station):
mvg_station = self.get_station(station)
if mvg_station:
mvgapi = MvgApi(mvg_station['id'])
return mvgapi.departures()
else:
logger.error("Station %s does not exist."%station)
Binary file modified mvg_live/mvg.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions mvg_live/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ plugin:
documentation: http://smarthomeng.de/user/plugins_doc/config/mvg_live.html
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1108867-neues-plugin-mvg_live

version: 1.5.1 # Plugin version
version: 1.6.0 # Plugin version
sh_minversion: 1.5 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: False # plugin supports multi instance
restartable: unknown
classname: MVG_Live # class containing the plugin
Expand Down
2 changes: 1 addition & 1 deletion mvg_live/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyMVGLive>=1.1.4
mvg>=1.1.2

0 comments on commit 881a4c8

Please sign in to comment.