diff --git a/src/pyopenweathermap/__init__.py b/src/pyopenweathermap/__init__.py index c888d81..86c8bb9 100644 --- a/src/pyopenweathermap/__init__.py +++ b/src/pyopenweathermap/__init__.py @@ -3,9 +3,10 @@ UnauthorizedError, TooManyRequestsError ) -from .client.owm_abstract_client import OWMClient +from .client.weather.abstract_weather_client import OWMWeatherClient from .client.owm_client_factory import create_owm_client from .weather import ( CurrentWeather, MinutelyWeatherForecast, HourlyWeatherForecast, DailyWeatherForecast, WeatherReport, DailyTemperature, WeatherCondition ) +from .client.air_pollution_client import AirPollutionReport from .air_pollution import CurrentAirPollution, AirPollutionReport diff --git a/src/pyopenweathermap/client/air_pollution_client.py b/src/pyopenweathermap/client/air_pollution_client.py index da01b2a..7c43589 100644 --- a/src/pyopenweathermap/client/air_pollution_client.py +++ b/src/pyopenweathermap/client/air_pollution_client.py @@ -1,13 +1,11 @@ -from .owm_abstract_client import OWMClient from ..data_converter import DataConverter from ..exception import UnauthorizedError -from ..weather import WeatherReport from ..air_pollution import AirPollutionReport CURRENT_AIR_POLLUTION_API_URL = 'https://api.openweathermap.org/data/2.5/air_pollution' FORECAST_API_URL = 'https://api.openweathermap.org/data/2.5/air_pollution/forecast' -class OWMAirPollutionClient(OWMClient): +class OWMAirPollutionClient: def __init__(self, api_key): super().__init__() self.api_key = api_key @@ -23,9 +21,6 @@ async def get_air_pollution(self, lat, lon) -> AirPollutionReport: return AirPollutionReport(current, hourly) - async def get_weather(self, lat, lon) -> WeatherReport: - raise NotImplementedError('Air Pollution client does not have get_weather()') - async def validate_key(self) -> bool: url = self._get_url(50.06, 14.44, 'api_type') try: diff --git a/src/pyopenweathermap/client/owm_client_factory.py b/src/pyopenweathermap/client/owm_client_factory.py index e4523fb..af91dd6 100644 --- a/src/pyopenweathermap/client/owm_client_factory.py +++ b/src/pyopenweathermap/client/owm_client_factory.py @@ -1,14 +1,14 @@ import logging -from .free_client import OWMFreeClient -from .onecall_client import OWMOneCallClient +from .weather.free_client import OWMFreeClient +from .weather.onecall_client import OWMOneCallClient from .air_pollution_client import OWMAirPollutionClient def create_owm_client(api_key, api_type, units="metric", lang='en'): logger = logging.getLogger(__name__) - logger.info('Initializing OWMClient with api type: ' + str(api_type)) + logger.info('Initializing OWM client with for type: ' + str(api_type)) if api_type == 'v3.0': return OWMOneCallClient(api_key, api_type, units, lang) if api_type == 'current' or api_type == 'forecast': @@ -16,4 +16,4 @@ def create_owm_client(api_key, api_type, units="metric", lang='en'): if api_type == 'air_pollution': return OWMAirPollutionClient(api_key) else: - raise Exception('Unsupported API type ' + str(api_type)) + raise Exception('Unsupported type ' + str(api_type)) diff --git a/src/pyopenweathermap/client/owm_abstract_client.py b/src/pyopenweathermap/client/weather/abstract_weather_client.py similarity index 62% rename from src/pyopenweathermap/client/owm_abstract_client.py rename to src/pyopenweathermap/client/weather/abstract_weather_client.py index ed5be00..2705ee7 100644 --- a/src/pyopenweathermap/client/owm_abstract_client.py +++ b/src/pyopenweathermap/client/weather/abstract_weather_client.py @@ -1,10 +1,9 @@ from abc import ABC, abstractmethod from ..weather import WeatherReport -from ..air_pollution import AirPollutionReport -from ..http_client import HttpClient +from ...http_client import HttpClient -class OWMClient(ABC): +class OWMWeatherClient(ABC): http_client: HttpClient def __init__(self) -> None: @@ -14,10 +13,6 @@ def __init__(self) -> None: async def get_weather(self, lat, lon) -> WeatherReport: pass - @abstractmethod - async def get_air_pollution(self, lat, lon) -> AirPollutionReport: - pass - @abstractmethod async def validate_key(self) -> bool: pass diff --git a/src/pyopenweathermap/client/free_client.py b/src/pyopenweathermap/client/weather/free_client.py similarity index 87% rename from src/pyopenweathermap/client/free_client.py rename to src/pyopenweathermap/client/weather/free_client.py index 0fe12ba..cf909f1 100644 --- a/src/pyopenweathermap/client/free_client.py +++ b/src/pyopenweathermap/client/weather/free_client.py @@ -1,4 +1,4 @@ -from .owm_abstract_client import OWMClient +from .abstract_weather_client import OWMWeatherClient from ..data_converter import DataConverter from ..exception import UnauthorizedError from ..weather import WeatherReport @@ -8,7 +8,7 @@ FORECAST_API_URL = 'https://api.openweathermap.org/data/2.5/forecast' -class OWMFreeClient(OWMClient): +class OWMFreeClient(OWMWeatherClient): def __init__(self, api_key, api_type, units="metric", lang='en'): super().__init__() self.api_key = api_key @@ -27,9 +27,6 @@ async def get_weather(self, lat, lon) -> WeatherReport: hourly = [DataConverter.free_to_hourly_weather_forecast(item) for item in json_response['list']] return WeatherReport(current,[], hourly, []) - async def get_air_pollution(self, lat, lon) -> AirPollutionReport: - raise NotImplementedError('free client does not have get_air_pollution()') - async def validate_key(self) -> bool: url = self._get_url(50.06, 14.44) try: diff --git a/src/pyopenweathermap/client/onecall_client.py b/src/pyopenweathermap/client/weather/onecall_client.py similarity index 87% rename from src/pyopenweathermap/client/onecall_client.py rename to src/pyopenweathermap/client/weather/onecall_client.py index 078a8ec..59891df 100644 --- a/src/pyopenweathermap/client/onecall_client.py +++ b/src/pyopenweathermap/client/weather/onecall_client.py @@ -1,13 +1,12 @@ -from .owm_abstract_client import OWMClient +from .abstract_weather_client import OWMWeatherClient from ..data_converter import DataConverter from ..exception import UnauthorizedError from ..weather import WeatherReport -from ..air_pollution import AirPollutionReport API_URL = 'https://api.openweathermap.org/data/3.0/onecall' -class OWMOneCallClient(OWMClient): +class OWMOneCallClient(OWMWeatherClient): def __init__(self, api_key, api_version, units="metric", lang='en'): super().__init__() self.api_key = api_key @@ -31,9 +30,6 @@ async def get_weather(self, lat, lon) -> WeatherReport: return WeatherReport(current, minutely, hourly, daily) - async def get_air_pollution(self, lat, lon) -> AirPollutionReport: - raise NotImplementedError('free client does not have get_air_pollution()') - async def validate_key(self) -> bool: url = (f"{self._get_url(50.06, 14.44)}" f"&exclude=current,minutely,hourly,daily,alerts)")