Esempio n. 1
0
    def search(self, term):
        """All stops and lines that match the search term.

        Arguments:
            term: serch term
        Returns:
            list of Stops & Lines
        """

        path = "/v2/search/%s" % urllib.quote(term)

        data = self._api_request(path)

        stop_factory = StopFactory(self)
        line_factory = LineFactory(self)

        out = []
        for result in data:
            if result['type'] == 'stop':
                out.append(stop_factory.create(**result['result']))
            elif result['type'] == 'line':
                out.append(line_factory.create(**result['result']))
            else:
                out.append(result)

        return out
Esempio n. 2
0
    def _process_departures(self, departures):
        """ common reponse parser for handling a list of departures """

        line_factory = LineFactory(self)
        stop_factory = StopFactory(self)
        run_factory = RunFactory(self)

        out = []
        for departure in departures:
            # - platform
            # -- direction
            # --- line
            platform_details = departure['platform']
            direction_details = platform_details.pop('direction')
            line_details = direction_details.pop('line')
            line = line_factory.create(**line_details)
            direction_details['line'] = line
            direction = Direction(**direction_details)
            platform_details['direction'] = direction
            # --- stop
            stop_details = platform_details.pop('stop')
            stop = stop_factory.create(**stop_details)
            platform_details['stop'] = stop
            platform = Platform(**platform_details)
            # - run
            run_details = departure['run']
            run = run_factory.create(**run_details)

            timetable = parse_datetime_tz(departure["time_timetable_utc"])
            if departure["time_realtime_utc"] is not None:
                realtime = parse_datetime_tz(departure["time_realtime_utc"])
            else:
                realtime = None

            if departure['flags']:
                flags = ', '.join([self.FLAGS[f] for f
                                   in departure['flags'].split('-')
                                   if f != 'E'])
            else:
                flags = None

            out.append({"platform": platform,
                        "run": run,
                        "flags": flags,
                        "time_timetable_utc": timetable,
                        "time_realtime_utc": realtime,
                        })
        return out
Esempio n. 3
0
    def lines_by_mode(self, mode, name=None):
        """ all the lines for a particular transport mode """
        base_path = "/v2/lines/mode/{mode}"

        mode_id = self.MODES[mode]

        path = base_path.format(mode=mode_id)

        if name is not None:
            path += "?name=%s" % name

        data = self._api_request(path)

        line_factory = LineFactory(self)

        out = []
        for line in data:
            out.append(line_factory.create(**line))

        return out