How to use the pyowm.utils.geo.assert_is_lat function in pyowm

To help you get started, we’ve selected a few pyowm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csparpa / pyowm / tests / unit / utils / test_geo.py View on Github external
def test_assert_is_lat(self):
        self.assertRaises(AssertionError, geo.assert_is_lat, '23.7')
        self.assertRaises(ValueError, geo.assert_is_lat, -100.0)
        self.assertRaises(ValueError, geo.assert_is_lat, 100.0)
        geo.assert_is_lat(90)
        geo.assert_is_lat(-90)
        geo.assert_is_lat(-45.6)
github csparpa / pyowm / tests / unit / utils / test_geo.py View on Github external
def test_assert_is_lat(self):
        self.assertRaises(AssertionError, geo.assert_is_lat, '23.7')
        self.assertRaises(ValueError, geo.assert_is_lat, -100.0)
        self.assertRaises(ValueError, geo.assert_is_lat, 100.0)
        geo.assert_is_lat(90)
        geo.assert_is_lat(-90)
        geo.assert_is_lat(-45.6)
github csparpa / pyowm / pyowm / weatherapi25 / weather_manager.py View on Github external
must be between -180.0 and 180.0
        :type lon_right: int/float
        :param zoom: zoom level (defaults to: 10)
        :type zoom: int
        :param cluster: use server clustering of points
        :type cluster: bool
        :returns: a list of *Observation* objects or ``None`` if no weather
            data is available
        :raises: *ParseResponseException* when OWM Weather API responses' data
            cannot be parsed, *APICallException* when OWM Weather API can not be
            reached, *ValueError* when coordinates values are out of bounds or
            negative values are provided for limit
        """
        geo.assert_is_lon(lon_left)
        geo.assert_is_lon(lon_right)
        geo.assert_is_lat(lat_bottom)
        geo.assert_is_lat(lat_top)
        assert type(zoom) is int, "'zoom' must be an int"
        if zoom <= 0:
            raise ValueError("'zoom' must greater than zero")
        assert type(cluster) is bool, "'cluster' must be a bool"
        params = {'bbox': ','.join([str(lon_left),
                                    str(lat_bottom),
                                    str(lon_right),
                                    str(lat_top),
                                    str(zoom)]),
                  'cluster': 'yes' if cluster else 'no'}
        _, json_data = self.http_client.get_json(BBOX_CITY_URI, params=params)
        return observation.Observation.from_dict_of_lists(json_data)
github csparpa / pyowm / pyowm / uvindexapi30 / uvindex_manager.py View on Github external
:type lat: int/float
        :param lon: the location's longitude, must be between -180.0 and 180.0
        :type lon: int/float
        :param start: the object conveying the time value for the start query boundary
        :type start: int, ``datetime.datetime`` or ISO8601-formatted string
        :param end: the object conveying the time value for the end query
            boundary (defaults to ``None``, in which case the current datetime
            will be used)
        :type end: int, ``datetime.datetime`` or ISO8601-formatted string
        :return: a list of *UVIndex* instances or empty list if data is not available
        :raises: *ParseResponseException* when OWM UV Index API responses' data
            cannot be parsed, *APICallException* when OWM UV Index API can not be
            reached, *ValueError* for wrong input values
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        assert start is not None
        start = formatting.timeformat(start, 'unix')
        if end is None:
            end = timestamps.now(timeformat='unix')
        else:
            end = formatting.timeformat(end, 'unix')
        params = {'lon': lon, 'lat': lat, 'start': start, 'end': end}
        json_data = self.uv_client.get_uvi_history(params)
        uvindex_list = [uvindex.UVIndex.from_dict(item) for item in json_data]
        return uvindex_list
github csparpa / pyowm / pyowm / weatherapi25 / weather_manager.py View on Github external
:type lon_right: int/float
        :param zoom: zoom level (defaults to: 10)
        :type zoom: int
        :param cluster: use server clustering of points
        :type cluster: bool
        :returns: a list of *Observation* objects or ``None`` if no weather
            data is available
        :raises: *ParseResponseException* when OWM Weather API responses' data
            cannot be parsed, *APICallException* when OWM Weather API can not be
            reached, *ValueError* when coordinates values are out of bounds or
            negative values are provided for limit
        """
        geo.assert_is_lon(lon_left)
        geo.assert_is_lon(lon_right)
        geo.assert_is_lat(lat_bottom)
        geo.assert_is_lat(lat_top)
        assert type(zoom) is int, "'zoom' must be an int"
        if zoom <= 0:
            raise ValueError("'zoom' must greater than zero")
        assert type(cluster) is bool, "'cluster' must be a bool"
        params = {'bbox': ','.join([str(lon_left),
                                    str(lat_bottom),
                                    str(lon_right),
                                    str(lat_top),
                                    str(zoom)]),
                  'cluster': 'yes' if cluster else 'no'}
        _, json_data = self.http_client.get_json(BBOX_CITY_URI, params=params)
        return observation.Observation.from_dict_of_lists(json_data)
github csparpa / pyowm / pyowm / airpollutionapi30 / airpollution_manager.py View on Github external
:type lon: int/float
        :param start: the object conveying the start value of the search time
            window start (defaults to ``None``). If not provided, the latest
            available Ozone value is retrieved
        :type start: int, ``datetime.datetime`` or ISO8601-formatted
            string
        :param interval: the length of the search time window starting at
           `start` (defaults to ``None``). If not provided, 'year' is used
        :type interval: str among: 'minute', 'hour', 'day', 'month, 'year'
        :return: an *Ozone* instance or ``None`` if data is not available
        :raises: *ParseResponseException* when OWM AirPollution API responses' data
            cannot be parsed, *APICallException* when OWM AirPollution API can not be
            reached, *ValueError* for wrong input values
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        params = {'lon': lon, 'lat': lat, 'start': start, 'interval': interval}
        json_data = self.ap_client.get_o3(params)
        oz = ozone.Ozone.from_dict(json_data)
        if interval is None:
            interval = 'year'
            oz._interval = interval
        return oz
github csparpa / pyowm / pyowm / webapi25 / owm25.py View on Github external
:type lon: int/float
        :param start: the object conveying the start value of the search time
            window start (defaults to ``None``). If not provided, the latest
            available NO2 samples value are retrieved
        :type start: int, ``datetime.datetime`` or ISO8601-formatted
            string
        :param interval: the length of the search time window starting at
           `start` (defaults to ``None``). If not provided, 'year' is used
        :type interval: str among: 'minute', 'hour', 'day', 'month, 'year'
        :return: a *NO2Index* instance or ``None`` if data is not available
        :raises: *ParseResponseException* when OWM web API responses' data
            cannot be parsed, *APICallException* when OWM web API can not be
            reached, *ValueError* for wrong input values
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        params = {'lon': lon, 'lat': lat, 'start': start, 'interval': interval}
        json_data = self._pollapi.get_no2(params)
        no2index = self._parsers['no2index'].parse_JSON(json_data)
        if interval is None:
            interval = 'year'
        no2index._interval = interval
        return no2index
github csparpa / pyowm / pyowm / webapi25 / owm25.py View on Github external
:type lat: int/float
        :param lon: the location's longitude, must be between -180.0 and 180.0
        :type lon: int/float
        :param start: the object conveying the time value for the start query boundary
        :type start: int, ``datetime.datetime`` or ISO8601-formatted string
        :param end: the object conveying the time value for the end query
            boundary (defaults to ``None``, in which case the current datetime
            will be used)
        :type end: int, ``datetime.datetime`` or ISO8601-formatted string
        :return: a list of *UVIndex* instances or empty list if data is not available
        :raises: *ParseResponseException* when OWM web API responses' data
            cannot be parsed, *APICallException* when OWM web API can not be
            reached, *ValueError* for wrong input values
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        assert start is not None
        start = timeformatutils.timeformat(start, 'unix')
        if end is None:
            end = timeutils.now(timeformat='unix')
        else:
            end = timeformatutils.timeformat(end, 'unix')
        params = {'lon': lon, 'lat': lat, 'start': start, 'end': end}
        json_data = self._uvapi.get_uvi_history(params)
        uvindex_list = self._parsers['uvindex_list'].parse_JSON(json_data)
        return uvindex_list
github csparpa / pyowm / pyowm / uvindexapi30 / uvindex_manager.py View on Github external
def uvindex_forecast_around_coords(self, lat, lon):
        """
        Queries for forecast Ultra Violet values in the next 8
        days in the surroundings of the provided geocoordinates.

        :param lat: the location's latitude, must be between -90.0 and 90.0
        :type lat: int/float
        :param lon: the location's longitude, must be between -180.0 and 180.0
        :type lon: int/float
        :return: a list of *UVIndex* instances or empty list if data is not available
        :raises: *ParseResponseException* when OWM UV Index API responses' data
            cannot be parsed, *APICallException* when OWM UV Index API can not be
            reached, *ValueError* for wrong input values
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        params = {'lon': lon, 'lat': lat}
        json_data = self.uv_client.get_uvi_forecast(params)
        uvindex_list = [uvindex.UVIndex.from_dict(item) for item in json_data]
        return uvindex_list
github csparpa / pyowm / pyowm / webapi25 / owm25.py View on Github external
:param lat: location's latitude, must be between -90.0 and 90.0
        :type lat: int/float
        :param lon: location's longitude, must be between -180.0 and 180.0
        :type lon: int/float
        :param limit: the maximum number of *Observation* items in the returned
            list (default is ``None``, which stands for any number of items)
        :param limit: int or ``None``
        :returns: a list of *Observation* objects or ``None`` if no weather
            data is available
        :raises: *ParseResponseException* when OWM web API responses' data
            cannot be parsed, *APICallException* when OWM web API can not be
            reached, *ValueError* when coordinates values are out of bounds or
            negative values are provided for limit
        """
        geo.assert_is_lon(lon)
        geo.assert_is_lat(lat)
        params = {'lon': lon, 'lat': lat, 'lang': self._language}
        if limit is not None:
            assert isinstance(limit, int), "'limit' must be an int or None"
            if limit < 1:
                raise ValueError("'limit' must be None or greater than zero")
            params['cnt'] = limit
        uri = http_client.HttpClient.to_url(FIND_OBSERVATIONS_URL,
                                            self._API_key,
                                            self._subscription_type,
                                            self._use_ssl)
        _, json_data = self._wapi.cacheable_get_json(uri, params=params)
        return self._parsers['observation_list'].parse_JSON(json_data)