diff --git a/tap_openweathermap/schemas/current_weather.py b/tap_openweathermap/schemas/current_weather.py index 76737f8..849ef63 100644 --- a/tap_openweathermap/schemas/current_weather.py +++ b/tap_openweathermap/schemas/current_weather.py @@ -1,51 +1,63 @@ -from singer_sdk.typing import ( - PropertiesList, - Property, - NumberType, - StringType, +from singer_sdk import typing as th + +from tap_openweathermap.schemas.weather import WeatherObject + +CurrentWeatherObject = th.PropertiesList( + th.Property("synced_at", th.DateTimeType), + th.Property( + "coord", + th.ObjectType( + th.Property("lon", th.NumberType), + th.Property("lat", th.NumberType), + ), + ), + th.Property("weather", th.ArrayType(WeatherObject)), + th.Property("base", th.StringType), + th.Property( + "main", + th.ObjectType( + th.Property("temp", th.NumberType), + th.Property("feels_like", th.NumberType), + th.Property("temp_min", th.NumberType), + th.Property("temp_max", th.NumberType), + th.Property("pressure", th.NumberType), + th.Property("humidity", th.NumberType), + ), + ), + th.Property("visibility", th.NumberType), + th.Property( + "wind", + th.ObjectType( + th.Property("speed", th.NumberType), + th.Property("deg", th.NumberType), + th.Property("gust", th.NumberType), + ), + ), + th.Property( + "rain", + th.ObjectType( + th.Property("1h", th.NumberType), + ), + ), + th.Property( + "clouds", + th.ObjectType( + th.Property("all", th.NumberType), + ), + ), + th.Property("dt", th.NumberType), + th.Property( + "sys", + th.ObjectType( + th.Property("type", th.NumberType), + th.Property("id", th.NumberType), + th.Property("country", th.StringType), + th.Property("sunrise", th.NumberType), + th.Property("sunset", th.NumberType), + ), + ), + th.Property("timezone", th.NumberType), + th.Property("id", th.NumberType), + th.Property("name", th.StringType), + th.Property("cod", th.NumberType), ) - -from tap_openweathermap.schemas.utils.custom_object import CustomObject - - -class CurrentWeatherCoordObject(CustomObject): - properties = PropertiesList( - Property("lon", NumberType), Property("lat", NumberType) - ) - - -class CurrentWeatherMainObject(CustomObject): - properties = PropertiesList( - Property("temp", NumberType), - Property("feels_like", NumberType), - Property("temp_min", NumberType), - Property("temp_max", NumberType), - Property("pressure", NumberType), - Property("humidity", NumberType), - ) - - -class CurrentWeatherWindObject(CustomObject): - properties = PropertiesList( - Property("speed", NumberType), - Property("deg", NumberType), - Property("gust", NumberType), - ) - - -class CurrentWeatherRainObject(CustomObject): - properties = PropertiesList(Property("1h", NumberType)) - - -class CurrentWeatherCloudsObject(CustomObject): - properties = PropertiesList(Property("all", NumberType)) - - -class CurrentWeatherSysObject(CustomObject): - properties = PropertiesList( - Property("type", NumberType), - Property("id", NumberType), - Property("country", StringType), - Property("sunrise", NumberType), - Property("sunset", NumberType), - ) diff --git a/tap_openweathermap/schemas/forecast_weather.py b/tap_openweathermap/schemas/forecast_weather.py index fad4694..37cc960 100644 --- a/tap_openweathermap/schemas/forecast_weather.py +++ b/tap_openweathermap/schemas/forecast_weather.py @@ -1,106 +1,106 @@ -from singer_sdk.typing import ( - PropertiesList, - Property, - ArrayType, - NumberType, - StringType, -) +from singer_sdk import typing as th -from tap_openweathermap.schemas.utils.custom_object import CustomObject from tap_openweathermap.schemas.weather import WeatherObject - -class ForecastCurrentObject(CustomObject): - properties = PropertiesList( - Property("dt", NumberType), - Property("sunrise", NumberType), - Property("sunset", NumberType), - Property("temp", NumberType), - Property("feels_like", NumberType), - Property("pressure", NumberType), - Property("humidity", NumberType), - Property("dew_point", NumberType), - Property("uvi", NumberType), - Property("clouds", NumberType), - Property("visibility", NumberType), - Property("wind_speed", NumberType), - Property("wind_deg", NumberType), - Property("wind_gust", NumberType), - Property("weather", WeatherObject), - ) - - -class ForecastMinutelyObject(CustomObject): - properties = ArrayType( - PropertiesList( - Property("dt", NumberType), Property("precipitation", NumberType) - ) - ) - - -class ForecastHourlyObject(CustomObject): - properties = ArrayType( - PropertiesList( - Property("dt", NumberType), - Property("temp", NumberType), - Property("feels_like", NumberType), - Property("pressure", NumberType), - Property("humidity", NumberType), - Property("dew_point", NumberType), - Property("uvi", NumberType), - Property("clouds", NumberType), - Property("visibility", NumberType), - Property("wind_speed", NumberType), - Property("wind_deg", NumberType), - Property("wind_gust", NumberType), - Property("weather", WeatherObject), - Property("pop", NumberType), - ) - ) - - -class ForecastTempObject(CustomObject): - properties = PropertiesList( - Property("day", NumberType), - Property("min", NumberType), - Property("max", NumberType), - Property("night", NumberType), - Property("eve", NumberType), - Property("morn", NumberType), - ) - - -class ForecastFeelsLikeObject(CustomObject): - properties = PropertiesList( - Property("day", NumberType), - Property("night", NumberType), - Property("eve", NumberType), - Property("morn", NumberType), - ) - - -class ForecastDailyObject(CustomObject): - properties = ArrayType( - PropertiesList( - Property("dt", NumberType), - Property("sunrise", NumberType), - Property("sunset", NumberType), - Property("moonrise", NumberType), - Property("moonset", NumberType), - Property("moonphase", NumberType), - Property("summary", StringType), - Property("temp", ForecastTempObject), - Property("feels_like", ForecastFeelsLikeObject), - Property("pressure", NumberType), - Property("humidity", NumberType), - Property("dew_point", NumberType), - Property("wind_speed", NumberType), - Property("wind_deg", NumberType), - Property("wind_gust", NumberType), - Property("weather", WeatherObject), - Property("clouds", NumberType), - Property("pop", NumberType), - Property("rain", NumberType), - Property("uvi", NumberType), - ) - ) +ForecastWeatherObject = th.PropertiesList( + th.Property("synced_at", th.DateTimeType), + th.Property("lat", th.NumberType), + th.Property("lon", th.NumberType), + th.Property("timezone", th.StringType), + th.Property("timezone_offset", th.NumberType), + th.Property( + "current", + th.ObjectType( + th.Property("dt", th.NumberType), + th.Property("sunrise", th.NumberType), + th.Property("sunset", th.NumberType), + th.Property("temp", th.NumberType), + th.Property("feels_like", th.NumberType), + th.Property("pressure", th.NumberType), + th.Property("humidity", th.NumberType), + th.Property("dew_point", th.NumberType), + th.Property("uvi", th.NumberType), + th.Property("clouds", th.NumberType), + th.Property("visibility", th.NumberType), + th.Property("wind_speed", th.NumberType), + th.Property("wind_deg", th.NumberType), + th.Property("wind_gust", th.NumberType), + th.Property("weather", th.ArrayType(WeatherObject)), + ), + ), + th.Property( + "minutely", + th.ArrayType( + th.ObjectType( + th.Property("dt", th.NumberType), + th.Property("precipitation", th.NumberType), + ) + ), + ), + th.Property( + "hourly", + th.ArrayType( + th.ObjectType( + th.Property("dt", th.NumberType), + th.Property("temp", th.NumberType), + th.Property("feels_like", th.NumberType), + th.Property("pressure", th.NumberType), + th.Property("humidity", th.NumberType), + th.Property("dew_point", th.NumberType), + th.Property("uvi", th.NumberType), + th.Property("clouds", th.NumberType), + th.Property("visibility", th.NumberType), + th.Property("wind_speed", th.NumberType), + th.Property("wind_deg", th.NumberType), + th.Property("wind_gust", th.NumberType), + th.Property("weather", th.ArrayType(WeatherObject)), + th.Property("pop", th.NumberType), + ) + ), + ), + th.Property( + "daily", + th.ArrayType( + th.ObjectType( + th.Property("dt", th.NumberType), + th.Property("sunrise", th.NumberType), + th.Property("sunset", th.NumberType), + th.Property("moonrise", th.NumberType), + th.Property("moonset", th.NumberType), + th.Property("moonphase", th.NumberType), + th.Property("summary", th.StringType), + th.Property( + "temp", + th.ObjectType( + th.Property("day", th.NumberType), + th.Property("min", th.NumberType), + th.Property("max", th.NumberType), + th.Property("night", th.NumberType), + th.Property("eve", th.NumberType), + th.Property("morn", th.NumberType), + ), + ), + th.Property( + "feels_like", + th.ObjectType( + th.Property("day", th.NumberType), + th.Property("night", th.NumberType), + th.Property("eve", th.NumberType), + th.Property("morn", th.NumberType), + ), + ), + th.Property("pressure", th.NumberType), + th.Property("humidity", th.NumberType), + th.Property("dew_point", th.NumberType), + th.Property("wind_speed", th.NumberType), + th.Property("wind_deg", th.NumberType), + th.Property("wind_gust", th.NumberType), + th.Property("weather", th.ArrayType(WeatherObject)), + th.Property("clouds", th.NumberType), + th.Property("pop", th.NumberType), + th.Property("rain", th.NumberType), + th.Property("uvi", th.NumberType), + ) + ), + ), +) diff --git a/tap_openweathermap/schemas/utils/__init__.py b/tap_openweathermap/schemas/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tap_openweathermap/schemas/utils/custom_object.py b/tap_openweathermap/schemas/utils/custom_object.py deleted file mode 100644 index 5545ce7..0000000 --- a/tap_openweathermap/schemas/utils/custom_object.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Base custom object defintion""" - -from singer_sdk.helpers._classproperty import classproperty -from singer_sdk.typing import JSONTypeHelper, PropertiesList - - -class CustomObject(JSONTypeHelper): - properties: PropertiesList - - @classproperty - def type_dict(cls) -> dict: - return cls.properties.to_dict() - - @classproperty - def schema(cls) -> dict: - return cls.type_dict diff --git a/tap_openweathermap/schemas/weather.py b/tap_openweathermap/schemas/weather.py index da8b70e..093401c 100644 --- a/tap_openweathermap/schemas/weather.py +++ b/tap_openweathermap/schemas/weather.py @@ -1,20 +1,8 @@ -from singer_sdk.typing import ( - PropertiesList, - Property, - ArrayType, - NumberType, - StringType, -) - -from tap_openweathermap.schemas.utils.custom_object import CustomObject +from singer_sdk import typing as th - -class WeatherObject(CustomObject): - properties = ArrayType( - PropertiesList( - Property("id", NumberType), - Property("main", StringType), - Property("description", StringType), - Property("icon", StringType), - ) - ) +WeatherObject = th.PropertiesList( + th.Property("id", th.NumberType), + th.Property("main", th.StringType), + th.Property("description", th.StringType), + th.Property("icon", th.StringType), +) diff --git a/tap_openweathermap/streams.py b/tap_openweathermap/streams.py index 26b34b4..2721803 100644 --- a/tap_openweathermap/streams.py +++ b/tap_openweathermap/streams.py @@ -4,29 +4,9 @@ from typing import Any, Dict, Optional from singer_sdk.streams import RESTStream -from singer_sdk.typing import ( - DateTimeType, - NumberType, - PropertiesList, - Property, - StringType, -) - -from tap_openweathermap.schemas.current_weather import ( - CurrentWeatherCloudsObject, - CurrentWeatherCoordObject, - CurrentWeatherMainObject, - CurrentWeatherRainObject, - CurrentWeatherSysObject, - CurrentWeatherWindObject, -) -from tap_openweathermap.schemas.forecast_weather import ( - ForecastCurrentObject, - ForecastDailyObject, - ForecastHourlyObject, - ForecastMinutelyObject, -) -from tap_openweathermap.schemas.weather import WeatherObject + +from tap_openweathermap.schemas.current_weather import CurrentWeatherObject +from tap_openweathermap.schemas.forecast_weather import ForecastWeatherObject class _SyncedAtStream(RESTStream): @@ -76,24 +56,7 @@ class CurrentWeatherStream(_CurrentWeatherStream): url_base = "https://api.openweathermap.org/data/2.5" name = "current_weather_stream" path = "/weather" - - schema = PropertiesList( - Property("synced_at", DateTimeType), - Property("coord", CurrentWeatherCoordObject), - Property("weather", WeatherObject), - Property("base", StringType), - Property("main", CurrentWeatherMainObject), - Property("visibility", NumberType), - Property("wind", CurrentWeatherWindObject), - Property("rain", CurrentWeatherRainObject), - Property("clouds", CurrentWeatherCloudsObject), - Property("dt", NumberType), - Property("sys", CurrentWeatherSysObject), - Property("timezone", NumberType), - Property("id", NumberType), - Property("name", StringType), - Property("cod", NumberType), - ).to_dict() + schema = CurrentWeatherObject.to_dict() class ForecastWeatherStream(_ForcastWeatherStream): @@ -103,17 +66,7 @@ class ForecastWeatherStream(_ForcastWeatherStream): name = "forecast_stream" path = "/onecall" extra_retry_statuses = () - schema = PropertiesList( - Property("synced_at", DateTimeType), - Property("lat", NumberType), - Property("lon", NumberType), - Property("timezone", StringType), - Property("timezone_offset", NumberType), - Property("current", ForecastCurrentObject), - Property("minutely", ForecastMinutelyObject), - Property("hourly", ForecastHourlyObject), - Property("daily", ForecastDailyObject), - ).to_dict() + schema = ForecastWeatherObject.to_dict() def response_error_message(self, response): return "\n".join(