コード例 #1
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_poi(self, **kwargs):
        """Obtain a list of POI in the given radius.

        Args:
            latitude (double): Latitude in decimal degrees.
            longitude (double): Longitude in decimal degrees.
            types (list[int] | int): POI IDs (or empty list to get all).
            radius (int): Radius (in meters) of the search.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Poi]), or message string
            in case of error.
        """
        # Endpoint parameters
        params = {
            'coordinateX': kwargs.get('longitude'),
            'coordinateY': kwargs.get('latitude'),
            'tipos': util.ints_to_string(kwargs.get('types')),
            'Radius': kwargs.get('radius'),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_poi', **params)

        # Funny endpoint, no status code
        if not util.check_result(result, 'poiList'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'poiList')
        return True, [emtype.Poi(**a) for a in values]
コード例 #2
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_stops_line(self, **kwargs):
        """Obtain information on the stops of the given lines.

        Arguments:
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.
            direction (str): Optional, either *forward* or *backward*.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Stop]), or message string
            in case of error.
        """
        # Endpoint parameters
        params = {
            'line': util.ints_to_string(kwargs.get('lines', [])),
            'direction': util.direction_code(kwargs.get('direction', '')),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_stops_line', **params)

        # Funny endpoint, no status code
        # Only interested in 'stop'
        if not util.check_result(result, 'stop'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'stop')
        return True, [emtype.Stop(**a) for a in values]
コード例 #3
0
    def get_timetable_lines(self, **kwargs):
        """Obtain information on lines for a travel.

        Args:
            day (int): Day of the month in format DD.
                The number is automatically padded if it only has one digit.
            month (int): Month number in format MM.
                The number is automatically padded if it only has one digit.
            year (int): Year number in format YYYY.
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.

        Returns:
            Status boolean and parsed response (list[TimetableLinesItem]),
            or message string in case of error.
        """
        # Endpoint parameters
        select_date = util.date_string(
            kwargs.get('day', '01'),
            kwargs.get('month', '01'),
            kwargs.get('year', '1970')
        )

        lines = util.ints_to_string(kwargs.get('lines', []))

        # Request
        params = {'SelectDate': select_date, 'Lines': lines}
        result = self.make_request('bus', 'get_timetable_lines', **params)

        if not util.check_result(result):
            return False, result.get('resultDescription', 'UNKNOWN ERROR')

        # Parse
        values = util.response_list(result, 'resultValues')
        return True, [emtype.TimetableLinesItem(**a) for a in values]
コード例 #4
0
ファイル: bus.py プロジェクト: rmed/pyemtmad
    def get_timetable_lines(self, **kwargs):
        """Obtain information on lines for a travel.

        Args:
            day (int): Day of the month in format DD.
                The number is automatically padded if it only has one digit.
            month (int): Month number in format MM.
                The number is automatically padded if it only has one digit.
            year (int): Year number in format YYYY.
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.

        Returns:
            Status boolean and parsed response (list[TimetableLinesItem]),
            or message string in case of error.
        """
        # Endpoint parameters
        select_date = util.date_string(
            kwargs.get('day', '01'),
            kwargs.get('month', '01'),
            kwargs.get('year', '1970')
        )

        lines = util.ints_to_string(kwargs.get('lines', []))

        # Request
        params = {'SelectDate': select_date, 'Lines': lines}
        result = self.make_request('bus', 'get_timetable_lines', **params)

        if not util.check_result(result):
            return False, result.get('resultDescription', 'UNKNOWN ERROR')

        # Parse
        values = util.response_list(result, 'resultValues')
        return True, [emtype.TimetableLinesItem(**a) for a in values]
コード例 #5
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_stops_line(self, **kwargs):
        """Obtain information on the stops of the given lines.

        Arguments:
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.
            direction (str): Optional, either *forward* or *backward*.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Stop]), or message string
            in case of error.
        """
        # Endpoint parameters
        params = {
            'line': util.ints_to_string(kwargs.get('lines', [])),
            'direction': util.direction_code(kwargs.get('direction', '')),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_stops_line', **params)

        # Funny endpoint, no status code
        # Only interested in 'stop'
        if not util.check_result(result, 'stop'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'stop')
        return True, [emtype.Stop(**a) for a in values]
コード例 #6
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_poi(self, **kwargs):
        """Obtain a list of POI in the given radius.

        Args:
            latitude (double): Latitude in decimal degrees.
            longitude (double): Longitude in decimal degrees.
            types (list[int] | int): POI IDs (or empty list to get all).
            radius (int): Radius (in meters) of the search.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Poi]), or message string
            in case of error.
        """
        # Endpoint parameters
        params = {
            'coordinateX': kwargs.get('longitude'),
            'coordinateY': kwargs.get('latitude'),
            'tipos': util.ints_to_string(kwargs.get('types')),
            'Radius': kwargs.get('radius'),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_poi', **params)

        # Funny endpoint, no status code
        if not util.check_result(result, 'poiList'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'poiList')
        return True, [emtype.Poi(**a) for a in values]
コード例 #7
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_info_line(self, **kwargs):
        """Obtain basic information on a bus line on a given date.

        Args:
            day (int): Day of the month in format DD.
                The number is automatically padded if it only has one digit.
            month (int): Month number in format MM.
                The number is automatically padded if it only has one digit.
            year (int): Year number in format YYYY.
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Line]), or message string
            in case of error.
        """
        # Endpoint parameters
        select_date = '%02d/%02d/%d' % (
            kwargs.get('day', '01'),
            kwargs.get('month', '01'),
            kwargs.get('year', '1970')
        )

        params = {
            'fecha': select_date,
            'line': util.ints_to_string(kwargs.get('lines', [])),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_info_line', **params)

        # Funny endpoint, no status code
        if not util.check_result(result, 'Line'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'Line')
        return True, [emtype.Line(**a) for a in values]
コード例 #8
0
ファイル: geo.py プロジェクト: rmed/pyemtmad
    def get_info_line(self, **kwargs):
        """Obtain basic information on a bus line on a given date.

        Args:
            day (int): Day of the month in format DD.
                The number is automatically padded if it only has one digit.
            month (int): Month number in format MM.
                The number is automatically padded if it only has one digit.
            year (int): Year number in format YYYY.
            lines (list[int] | int): Lines to query, may be empty to get
                all the lines.
            lang (str): Language code (*es* or *en*).

        Returns:
            Status boolean and parsed response (list[Line]), or message string
            in case of error.
        """
        # Endpoint parameters
        select_date = '%02d/%02d/%d' % (kwargs.get(
            'day', '01'), kwargs.get('month', '01'), kwargs.get(
                'year', '1970'))

        params = {
            'fecha': select_date,
            'line': util.ints_to_string(kwargs.get('lines', [])),
            'cultureInfo': util.language_code(kwargs.get('lang'))
        }

        # Request
        result = self.make_request('geo', 'get_info_line', **params)

        # Funny endpoint, no status code
        if not util.check_result(result, 'Line'):
            return False, 'UNKNOWN ERROR'

        # Parse
        values = util.response_list(result, 'Line')
        return True, [emtype.Line(**a) for a in values]
コード例 #9
0
ファイル: bus.py プロジェクト: rmed/pyemtmad
    def get_nodes_lines(self, **kwargs):
        """Obtain stop IDs, coordinates and line information.

        Args:
            nodes (list[int] | int): nodes to query, may be empty to get
                all nodes.

        Returns:
            Status boolean and parsed response (list[NodeLinesItem]), or message
            string in case of error.
        """
        # Endpoint parameters
        params = {'Nodes': util.ints_to_string(kwargs.get('nodes', []))}

        # Request
        result = self.make_request('bus', 'get_nodes_lines', **params)

        if not util.check_result(result):
            return False, result.get('resultDescription', 'UNKNOWN ERROR')

        # Parse
        values = util.response_list(result, 'resultValues')
        return True, [emtype.NodeLinesItem(**a) for a in values]
コード例 #10
0
    def get_nodes_lines(self, **kwargs):
        """Obtain stop IDs, coordinates and line information.

        Args:
            nodes (list[int] | int): nodes to query, may be empty to get
                all nodes.

        Returns:
            Status boolean and parsed response (list[NodeLinesItem]), or message
            string in case of error.
        """
        # Endpoint parameters
        params = {'Nodes': util.ints_to_string(kwargs.get('nodes', []))}

        # Request
        result = self.make_request('bus', 'get_nodes_lines', **params)

        if not util.check_result(result):
            return False, result.get('resultDescription', 'UNKNOWN ERROR')

        # Parse
        values = util.response_list(result, 'resultValues')
        return True, [emtype.NodeLinesItem(**a) for a in values]