def test(_start: str, _dest: str): now = datetime.now() # for debug proposes # now = datetime(2020, 3, 30, 17, 25, 0, 0) test_start = mvg_api.get_id_for_station(_start) test_dest = mvg_api.get_id_for_station(_dest) print("ID test_start: ", test_start) print("ID test_dest: ", test_dest) print("\n") routes = mvg_api.get_route(test_start, test_dest, now) for e in routes: print(e) print_route(e) print("\n") return
def display_departures(station_name, limit=10, mode=None): station_id = mvg.get_id_for_station(station_name) assert station_id is not None, f"Station {station_name} not found!" departuresJSON = mvg.get_departures(station_id) departures = [] if mode is not None: for d in departuresJSON: if mode.upper() in d['product']: departures += [Departure(d)] else: departures = [Departure(i) for i in departuresJSON] departures = departures[:limit] print('\nStation: ' + station_name + '\n') table = PrettyTable(['Line', 'Destination', 'Departure (min)']) # table.set_deco(Texttable.HEADER) rows = [] # rows.append(['Line', 'Destination', 'Departure (min)']) for dep in departures: rows.append([ dep.get_label_colored(), dep.destination, dep.departure_time_minutes ]) table.add_rows(rows) # print( color(table.draw(), fore=MVG_FG, back=MVG_BG) ) print(table)
def get_garching(): ''' retrieves and prepares departuretimes for Garching station ''' departures = None with Timeout(5, False): try: station_int = int(get_id_for_station("Garching")[-3:]) departures = get_departures(station_int) except Exception as e: print('exeption: ') print(e) return [' '] * 4 if departures is None: return [' '] * 4 towards_garching = [] towards_munich = [] for departure in departures: if (departure['product'] == 'UBAHN' and len(towards_garching) + len(towards_munich) != 4): if departure['destination'][0] == 'G': if len(towards_garching) < 2: towards_garching.append( "\rin " + str(departure['departureTimeMinutes']) + ' min') elif len(towards_munich) < 2: towards_munich.append("\rin " + str(departure['departureTimeMinutes']) + ' min') for _ in range(2 - len(towards_garching)): towards_garching.append(' ') for _ in range(2 - len(towards_munich)): towards_munich.append(' ') return towards_garching + towards_munich
def get_info(station): global print_information try: Id = mvg_api.get_id_for_station(station) if Id: destinations = mvg_api.get_departures(Id) print_information(destinations) else: print('\n ' + bg(255,0,0) + ' The station does not exists ' + rs.bg + '\n') except: print('\n ' + bg(255,0,0) + ' Something wrong has happened ' + rs.bg + '\n')
def get_stieglitz(): ''' retrieves and prepares departuretimes for LST station ''' departures = None with Timeout(5, False): try: station_int = int(get_id_for_station("Lehrer Stieglitz Str")[-4:]) departures = get_departures(station_int) except: return [' '] * 4 if departures is None: return [' '] * 4 stieglitz_str = [''] * 4 j = 0 for departure in departures: if j < 4: stieglitz_str[j] = (departure['label'] + " " + departure['destination'] + "\r" + 'in' + ' ' + str(departure['departureTimeMinutes']) + '' + 'min') j += 1 return stieglitz_str
def get_next_departures() -> List[MyEntry]: Logger.info("Model.get_next_departures: started") _now = datetime.now() # _now = datetime(2020, 3, 31, 16, 15, 0, 0) _list: List[MyEntry] = [] try: _start = mvg_api.get_id_for_station(start_str) _dest = mvg_api.get_id_for_station(destination_str) if _start is None or _dest is None: raise ValueError('Route nicht definiert.', _start, _dest) _routes = mvg_api.get_route(_start, _dest, _now) for c in range(amount): _list.append(process_route(_routes[c])) Logger.info("Model.get_next_departures: normal fetch") except requests.exceptions.ConnectionError: Logger.info("Model.get_next_departures: Connectionerror") # error entry _error_entry: MyEntry = MyEntry() _error_entry.img_ok_path = res_path + ok_path + resources_dict.get( "WARNING") + ok_ext _error_entry.img_N_path = res_path + notification_path + resources_dict.get( "WARNING") + notification_ext _error_entry.label = 'Verbindungsfehler' _error_entry.destination = '.' # help entry _help_entry: MyEntry = MyEntry() _help_entry.img_ok_path = res_path + ok_path + resources_dict.get( "WARNING") + ok_ext _help_entry.img_N_path = res_path + notification_path + resources_dict.get( "WARNING") + notification_ext _help_entry.destination = '.' _help_entry.label = 'WLAN überprüfen' # append _list.append(_error_entry) _list.append(_help_entry) except ValueError as verror: Logger.info("Model.get_next_departures: Valueerror") # error entry _error_entry: MyEntry = MyEntry() _error_entry.img_ok_path = res_path + ok_path + resources_dict.get( "WARNING") + ok_ext _error_entry.img_N_path = res_path + notification_path + resources_dict.get( "WARNING") + notification_ext _error_entry.destination = '!' if verror.args[1] is None: _error_entry.label = 'Startort unbekannt' elif verror.args[2] is None: _error_entry.label = 'Zielort unbekannt' # help entry _help_entry: MyEntry = MyEntry() _help_entry.img_ok_path = res_path + ok_path + resources_dict.get( "WARNING") + ok_ext _help_entry.img_N_path = res_path + notification_path + resources_dict.get( "WARNING") + notification_ext _help_entry.destination = '!' _help_entry.label = 'Überprüfe die Einstellungen' # append _list.append(_error_entry) _list.append(_help_entry) finally: Logger.info("Model.get_next_departures: finished!") return _list
def get_id(dafuq): # convert station name to ID sid = mvg_api.get_id_for_station(dafuq) return sid
class GridFrame(wx.Frame): X_POS = 3800 Y_POS = 0 STATION = "Richard-Strauss-Straße" STATIONID = mvg_api.get_id_for_station(STATION) ALLOWED_LABLES = ["U4"] FORBIDDEN_LABELS = [] def __init__(self): # GUI Implementation wx.Frame.__init__(self, parent=None, title=self.STATION, size=(315, 450)) icon = wx.Icon() icon.CopyFromBitmap(wx.Bitmap("icon.ico", wx.BITMAP_TYPE_ANY)) self.SetIcon(icon) self.SetPosition((self.X_POS, self.Y_POS)) panel = wx.Panel(self, wx.ID_ANY) self.index = 0 self.list_ctrl = wx.ListCtrl(panel, size=(-1, 500), style=wx.LC_REPORT | wx.BORDER_SUNKEN) self.list_ctrl.InsertColumn(0, 'Linie', width=40) self.list_ctrl.InsertColumn(1, 'Ziel', width=180) self.list_ctrl.InsertColumn(2, 'min', width=50) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.list_ctrl, 0, wx.ALL | wx.EXPAND, 5) panel.SetSizer(sizer) # Start of Logic self.depatures = mvg_api.get_departures(self.STATIONID) self.deltas = [] self.filterdepatures() # Thread is reloading the depatures destloader = threading.Thread(target=self.destinationreload) destloader.daemon = True destloader.start() # Thread who is counting down the time timecounter = threading.Thread(target=self.timecounter) timecounter.daemon = True timecounter.start() def destinationreload(self): def hexToWxColour(h): h = h.lstrip('#') rgb = tuple(int(h[i:i + 2], 16) for i in (0, 2, 4)) return wx.Colour(rgb[0], rgb[1], rgb[2], 255) def asigndepatures(): self.list_ctrl.DeleteAllItems() self.deltas.clear() t = time.time() for i, depature in enumerate(self.depatures): self.list_ctrl.InsertItem(i, self.depatures[i]['label']) self.list_ctrl.SetItem(i, 1, self.depatures[i]['destination']) self.list_ctrl.SetItemColumnImage(i, 0, 0) self.list_ctrl.SetItemBackgroundColour( i, hexToWxColour(self.depatures[i]['lineBackgroundColor'])) self.deltas.append( int(self.depatures[i]['departureTime'] / 1000 - t)) asigndepatures() while True: if len(self.depatures) > 0: sleeptime = (self.depatures[0]['departureTime'] / 1000) - time.time() if sleeptime > 0: time.sleep(sleeptime) else: time.sleep(10) ndepatures = mvg_api.get_departures(self.STATIONID) if ndepatures[0] != self.depatures[0]: self.depatures = ndepatures self.filterdepatures() asigndepatures() else: time.sleep(300) def timecounter(self): while True: for i, d in enumerate(self.deltas): mins, secs = divmod(self.deltas[i], 60) t = '{:02d}:{:02d}'.format(mins, secs) self.list_ctrl.SetItem(i, 2, t) self.deltas[i] -= 1 time.sleep(1) def filterdepatures(self): running = True while running: running = True for i, d in enumerate(self.depatures): if len(self.depatures) == 1: i = 0 d = self.depatures[i] running = False if d['label'] not in self.ALLOWED_LABLES or d[ 'label'] in self.FORBIDDEN_LABELS: del self.depatures[i] break if d['departureTimeMinutes'] > 30: del self.depatures[i] break running = False break
# coding=utf-8 import mvg_api as mvg station_id = mvg.get_id_for_station("Obersendling") departures = mvg.get_departures(station_id) for departure in departures: print(departure['product'] + departure['label'] + "\t" + departure['destination'] + "\t" + str(departure['departureTimeMinutes'])) # print(get_nearby_stations(48.0933264, 11.537161699999999)) # print(get_route((48.1267, 11.62009), 2, max_walk_time_to_dest=12, max_walk_time_to_start=15))
def get_id(station): sid = mvg_api.get_id_for_station(station) return sid
import mvg_api x=mvg_api.get_id_for_station("Hohenzollern Platz") print(x)
def get_id_of_station(station_name): return mvg_api.get_id_for_station(station_name)
import math import numpy import mvg_api station_id = mvg_api.get_id_for_station('Sendlnger Tor') abfahrten_rohdaten = mvg_api.get_departures(station_id) #abfahrten_gesamt = numpy.array([1,1],[1,1]) tram_18_schwansee = ['TRAM', '18', 'Schwanseestraße'] tram_18_gondrell = ['TRAM', '18', 'Gondrellplatz'] for x in range(len(abfahrten_rohdaten)): if abfahrten_rohdaten[x].get("product") == tram_18_schwansee[0] and abfahrten_rohdaten[x].get("label") == tram_18_schwansee[1] \ and abfahrten_rohdaten[x].get("destination") == tram_18_schwansee[2] : zeit = abfahrten_rohdaten[x].get("departureTimeMinutes") if zeit > 60: tram_18_schwansee.append( str(math.trunc(zeit / 60)) + 'h ' + str(math.trunc(zeit % 60)) + 'm') else: tram_18_schwansee.append(zeit) i = 0 while i < len(tram_18_schwansee): print(tram_18_schwansee[i]) i += 1
from Tkinter import * import mvg_api import threading import time #Get Departures idStation = mvg_api.get_id_for_station("Ostbahnhof") #Set Types to show typesToShow = ['u', 'b', 's'] #Start TKinter dialog top = Tk() #Define Threading class class myThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): while not stopEvent.is_set(): updateTimes() stopEvent.wait(30) def exitButton(): print "Exit" stopEvent.set() top.destroy()