How to use the pyowm.webapi25.location.Location 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 / webapi25 / test_owm25.py View on Github external
def test_daily_forecast_at_id(self):
        original_func = HttpClient.cacheable_get_json
        HttpClient.cacheable_get_json = \
            self.mock_api_call_returning_daily_forecast_at_id
        result = \
            self.__test_instance.daily_forecast_at_id(2643743, 2)
        HttpClient.cacheable_get_json = original_func
        self.assertTrue(isinstance(result, Forecaster))
        forecast = result.get_forecast()
        self.assertTrue(isinstance(forecast, Forecast))
        self.assertTrue(forecast.get_interval() is not None)
        self.assertTrue(forecast.get_reception_time() is not None)
        self.assertTrue(isinstance(forecast.get_location(), Location))
        self.assertEqual(1, len(forecast))
        for weather in forecast:
            self.assertTrue(isinstance(weather, Weather))
github csparpa / pyowm / tests / unit / webapi25 / test_cityidregistry.py View on Github external
result = self._instance.locations_for("Abbeville", country='JP')
        self.assertEquals(0, len(result))

        result = self._instance.locations_for("Abbeville", country='US')
        self.assertEquals(4, len(result))
        self._assertLocationsEqual(
            Location('Abbeville', -83.306824, 31.992121, 4178992, 'US'),
            result[0])
        self._assertLocationsEqual(
            Location('Abbeville', -92.134293, 29.974649, 4314295, 'US'),
            result[1])
        self._assertLocationsEqual(
            Location('Abbeville', -82.379013, 34.178169, 4568985, 'US'),
            result[2])
        self._assertLocationsEqual(
            Location('Abbeville', -85.250488, 31.57184, 4829449, 'US'),
            result[3])

        result = self._instance.locations_for("Abbeville", country='FR')
        self.assertEquals(1, len(result))
        self._assertLocationsEqual(
            Location("Abbeville", 1.83333, 50.099998, 3038789, 'FR'),
            result[0])

        CityIDRegistry._get_lines = ref_to_original
github csparpa / pyowm / tests / unit / webapi25 / test_location.py View on Github external
"""

import unittest
from pyowm.webapi25.location import Location, location_from_dictionary
from tests.unit.webapi25.json_test_dumps import LOCATION_JSON_DUMP
from tests.unit.webapi25.xml_test_dumps import LOCATION_XML_DUMP


class TestLocation(unittest.TestCase):

    __test_name = 'London'
    __test_lon = 12.3
    __test_lat = 43.7
    __test_ID = 1234
    __test_country = 'UK'
    __test_instance = Location(__test_name, __test_lon, __test_lat, __test_ID,
                               __test_country)

    def test_init_fails_when_lat_or_lon_are_none(self):
        self.assertRaises(ValueError, Location, 'London', None, 43.7, 1234)
        self.assertRaises(ValueError, Location, 'London', 200.0, None, 1234)

    def test_init_fails_when_coordinates_are_out_of_bounds(self):
        """
        Test failure when providing: lon < -180, lon > 180, lat < -90, lat > 90
        """
        self.assertRaises(ValueError, Location, 'London', -200.0, 43.7, 1234)
        self.assertRaises(ValueError, Location, 'London', 200.0, 43.7, 1234)
        self.assertRaises(ValueError, Location, 'London', 12.3, -100.0, 1234)
        self.assertRaises(ValueError, Location, 'London', 12.3, 100.0, 1234)

    def test_from_dictionary(self):
github csparpa / pyowm / tests / unit / webapi25 / test_location.py View on Github external
def test_getters_return_expected_data(self):
        instance = Location(self.__test_name, self.__test_lon, self.__test_lat,
                            self.__test_ID, self.__test_country)
        self.assertEqual(instance.get_name(), self.__test_name)
        self.assertEqual(instance.get_lon(), self.__test_lon)
        self.assertEqual(instance.get_lat(), self.__test_lat)
        self.assertEqual(instance.get_ID(), self.__test_ID)
        self.assertEqual(instance.get_country(), self.__test_country)
github csparpa / pyowm / tests / unit / webapi25 / test_cityidregistry.py View on Github external
Location('Abbeville', -83.306824, 31.992121, 4178992, 'US'),
            result[0])
        self._assertLocationsEqual(
            Location('Abbeville', -92.134293, 29.974649, 4314295, 'US'),
            result[1])
        self._assertLocationsEqual(
            Location('Abbeville', -82.379013, 34.178169, 4568985, 'US'),
            result[2])
        self._assertLocationsEqual(
            Location('Abbeville', -85.250488, 31.57184, 4829449, 'US'),
            result[3])

        result = self._instance.locations_for("Abbeville", country='FR')
        self.assertEquals(1, len(result))
        self._assertLocationsEqual(
            Location("Abbeville", 1.83333, 50.099998, 3038789, 'FR'),
            result[0])

        CityIDRegistry._get_lines = ref_to_original
github csparpa / pyowm / tests / unit / webapi25 / test_cityidregistry.py View on Github external
def test_locations_for_restricted_to_country(self):
        ref_to_original = CityIDRegistry._get_lines
        CityIDRegistry._get_lines = self._mock_get_lines_with_homonymies

        result = self._instance.locations_for("Abbeville", country='JP')
        self.assertEquals(0, len(result))

        result = self._instance.locations_for("Abbeville", country='US')
        self.assertEquals(4, len(result))
        self._assertLocationsEqual(
            Location('Abbeville', -83.306824, 31.992121, 4178992, 'US'),
            result[0])
        self._assertLocationsEqual(
            Location('Abbeville', -92.134293, 29.974649, 4314295, 'US'),
            result[1])
        self._assertLocationsEqual(
            Location('Abbeville', -82.379013, 34.178169, 4568985, 'US'),
            result[2])
        self._assertLocationsEqual(
            Location('Abbeville', -85.250488, 31.57184, 4829449, 'US'),
            result[3])

        result = self._instance.locations_for("Abbeville", country='FR')
        self.assertEquals(1, len(result))
        self._assertLocationsEqual(
            Location("Abbeville", 1.83333, 50.099998, 3038789, 'FR'),
            result[0])

        CityIDRegistry._get_lines = ref_to_original
github csparpa / pyowm / pyowm / webapi25 / parsers / uvindexparser.py View on Github external
"""
        if JSON_string is None:
            raise parse_response_error.ParseResponseError('JSON data is None')
        d = json.loads(JSON_string)
        try:
            # -- reference time
            reference_time = d['date']

            # -- reception time (now)
            reception_time = timeutils.now('unix')

            # -- location
            lon = float(d['lon'])
            lat = float(d['lat'])
            place = location.Location(None, lon, lat, None)

            # -- UV intensity
            uv_intensity = float(d['value'])

        except KeyError:
            raise parse_response_error.ParseResponseError(
                      ''.join([__name__, ': impossible to parse UV Index']))

        return uvindex.UVIndex(reference_time, place, uv_intensity,
                               reception_time)
github csparpa / pyowm / pyowm / webapi25 / jsonparser.py View on Github external
if 'city' in d:
        data = d['city']
    else:
        data = d
    try:
        name = data['name']
        lon = data['coord']['lon']
        lat = data['coord']['lat']
        ID = int(data['id'])
        if 'country' in data:
            country = data['country']
    except KeyError:
        raise ParseResponseError(''.join([__name__,': impossible to read ' \
              'location info from JSON data', linesep, str(data)]))
    else:
        return Location(name, lon, lat, ID, country)
github csparpa / pyowm / pyowm / webapi25 / parsers / so2indexparser.py View on Github external
"""
        if JSON_string is None:
            raise parse_response_error.ParseResponseError('JSON data is None')
        d = json.loads(JSON_string)
        try:
            # -- reference time (strip away Z and T on ISO8601 format)
            t = d['time'].replace('Z', '+00').replace('T', ' ')
            reference_time = timeformatutils._ISO8601_to_UNIXtime(t)

            # -- reception time (now)
            reception_time = timeutils.now('unix')

            # -- location
            lon = float(d['location']['longitude'])
            lat = float(d['location']['latitude'])
            place = location.Location(None, lon, lat, None)

            # -- SO2 samples
            so2_samples = d['data']

        except KeyError:
            raise parse_response_error.ParseResponseError(
                      ''.join([__name__, ': impossible to parse COIndex']))

        return so2index.SO2Index(reference_time, place, None, so2_samples,
                                 reception_time)