Ejemplo n.º 1
0
    def render_post(self, request):
        station_name = request.payload.decode('UTF-8')
        stations = Station.search_by_name(station_name)

        if len(station_name) < 4:
            payload = 'Search string to short'
            if len(station_name) == 0:
                payload = 'Missing search string'
            return aiocoap.Message(code=aiocoap.NOT_FOUND, payload=payload.encode('ascii'))

        if stations:
            payload = str([s['name'] for s in stations])
            for station in stations:
                if station['name'] == station_name:
                    stations = [station]

            if len(stations) == 1:
                station = stations[0]
                dep = Departures(station.get_stops())
                dep.refresh()
                payload = json.dumps(dep, ensure_ascii=False, default=json_serializer.default)
        else:
            return aiocoap.Message(code=aiocoap.NOT_FOUND, payload='Station not found'.encode('ascii'))

        response = aiocoap.Message(code=aiocoap.CONTENT, payload=payload.encode('UTF-8'))
        response.opt.content_format = aiocoap.numbers.media_types_rev['application/json']
        return response
Ejemplo n.º 2
0
    def get(self, name):
        stations = Station.search_by_name(name, exact=True)

        rbl = []
        for st in stations:
            rbl += list(st.get_stops())

        departures = Departures.get_by_stops(rbl)

        result_dicts = []
        for station in sorted(departures.values(), key=itemgetter('name')):
            for departure in sorted(station['departures'], key=itemgetter('countdown')):
                result_dicts.append(departure)

        return result_dicts
Ejemplo n.º 3
0
    def get(self, name):
        stations = Station.search_by_name(name, exact=True)

        rbl = []
        for st in stations:
            rbl += list(st.get_stops())

        departures = Departures.get_by_stops(rbl)

        result_dicts = []
        for station in sorted(departures.values(), key=itemgetter('name')):
            for departure in sorted(station['departures'], key=itemgetter('countdown')):
                if not departure['line']['colour']:
                    departure['line']['colour'] = 'transparent'
                result_dicts.append(departure)

        return result_dicts
Ejemplo n.º 4
0
        for direction in l.get_stations():
            print()
            print('-'*12)
            print(inred('Direction:'), i)
            print('-'*12)
            print()
            i += 1
            for station in direction:
                print(station['name'])

if args.deps:
    rbl = []
    for st in stations:
        rbl += list(st.get_stops())

    deps = Departures.get_by_stops(rbl)

    for station in sorted(deps.values(), key=itemgetter('name')):
        print()
        print('='*len(station['name']))
        print(ingreen(station['name']))
        print('='*len(station['name']))

        for departure in sorted(station['departures'], key=itemgetter('countdown')):
            dep_text = departure['line']['name'].ljust(6)
            dep_text += departure['line']['towards'].ljust(20)
            if departure['line']['barrierFree']:
                dep_text += inblue(str(departure['countdown']).rjust(4))
            else:
                dep_text += inred(str(departure['countdown']).rjust(4))