예제 #1
0
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)
예제 #2
0
    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)
예제 #3
0
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
예제 #4
0
파일: mv.py 프로젝트: zepptron/mvg-checker
def get_stuff(string):
    get = mvg_api.get_departures(get_id(string))
    summary = {}
    f = 0
    for i in get:
        f = f + 1
        summary[f] = {
            'label': i['label'],
            'product': i['product'],
            'destination': i['destination'],
            'departure': i['departureTimeMinutes']
        }
    return summary
예제 #5
0
def updateTimes():

    departures = mvg_api.get_departures(idStation)

    #Fill dialog with departures
    print "Update Times..."

    #Only show departures of selected products
    filteredDepartures = []
    for departure in departures:
        strProduct = departure['product']
        if strProduct in typesToShow:
            filteredDepartures.append(departure)

    #depIndex=0
    #for departure in filteredDepartures:
    for depIndex in range(12):

        if depIndex < len(filteredDepartures):
            departure = filteredDepartures[depIndex]

            #Get information from mvg_api
            strDestination = departure['destination'][:17]
            strProduct = departure['product']
            strLabel = departure['label']
            strLineBackgroundColor = departure['lineBackgroundColor']
            strDepartureMin = departure['departureTimeMinutes']

            strText = strProduct, strLabel, strDestination, strDepartureMin

        else:
            strProduct = ''
            strLabel = ''
            strLineBackgroundColor = 'lightgrey'
            strDestination = ''
            strDepartureMin = ''

        #Write information in labels
        timeEntryDict = timeTableEntries[depIndex]
        varLine = timeEntryDict['Line']
        varLine.set(strProduct + strLabel)
        labelLine = timeEntryDict['labelLine']
        labelLine.config(bg=strLineBackgroundColor)

        varDestination = timeEntryDict['Destination']
        varDestination.set(strDestination)

        varTimeLeft = timeEntryDict['TimeLeft']
        varTimeLeft.set(strDepartureMin)
예제 #6
0
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')
예제 #7
0
    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()
예제 #8
0
파일: handler.py 프로젝트: zepptron/sls-mvg
def get_json(event):
    # check if url params are set and correct
    try:
        params = event['queryStringParameters']
        try:
            station = params['station']
        except KeyError:
            msg = {"error": "key must be 'station'"}
            return (msg)
    except KeyError:
        msg = {"error": "no valid params set!"}
        return (msg)

    # try to get station ID
    try:
        gett0r = mvg_api.get_departures(get_id(station))
    except TypeError:
        msg = {"error": "station name " + station + " not valid."}
        return (msg)

    # create dict of departures based on station ID
    summary = {}
    f = 0
    for i in gett0r:
        f += 1
        try:
            summary[f] = {
                "label": i['label'],
                "product": i['product'],
                "destination": i['destination'],
                "departure": i['departureTimeMinutes']
            }
        except KeyError as e:
            msg = {"error": "key is unknown: " + e + ""}
            return (msg)
    return summary
예제 #9
0
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
예제 #10
0
# 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))
예제 #11
0
def get_departures(station_id):
    return mvg_api.get_departures(station_id)
예제 #12
0
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