python-google-weather-api 0.0.9__py3-none-any.whl → 0.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_weather_api/__init__.py +2 -0
- google_weather_api/api.py +23 -17
- google_weather_api/exceptions.py +4 -0
- google_weather_api/model.py +7 -6
- {python_google_weather_api-0.0.9.dist-info → python_google_weather_api-0.0.10.dist-info}/METADATA +1 -1
- python_google_weather_api-0.0.10.dist-info/RECORD +10 -0
- python_google_weather_api-0.0.9.dist-info/RECORD +0 -10
- {python_google_weather_api-0.0.9.dist-info → python_google_weather_api-0.0.10.dist-info}/WHEEL +0 -0
- {python_google_weather_api-0.0.9.dist-info → python_google_weather_api-0.0.10.dist-info}/licenses/LICENSE +0 -0
- {python_google_weather_api-0.0.9.dist-info → python_google_weather_api-0.0.10.dist-info}/top_level.txt +0 -0
google_weather_api/__init__.py
CHANGED
|
@@ -4,6 +4,7 @@ from .api import GoogleWeatherApi
|
|
|
4
4
|
from .exceptions import (
|
|
5
5
|
GoogleWeatherApiAuthError,
|
|
6
6
|
GoogleWeatherApiConnectionError,
|
|
7
|
+
GoogleWeatherApiConnectionTimeoutError,
|
|
7
8
|
GoogleWeatherApiError,
|
|
8
9
|
GoogleWeatherApiResponseError,
|
|
9
10
|
)
|
|
@@ -50,6 +51,7 @@ __all__ = [
|
|
|
50
51
|
"GoogleWeatherApi",
|
|
51
52
|
"GoogleWeatherApiAuthError",
|
|
52
53
|
"GoogleWeatherApiConnectionError",
|
|
54
|
+
"GoogleWeatherApiConnectionTimeoutError",
|
|
53
55
|
"GoogleWeatherApiError",
|
|
54
56
|
"GoogleWeatherApiResponseError",
|
|
55
57
|
"HourlyForecastResponse",
|
google_weather_api/api.py
CHANGED
|
@@ -11,6 +11,7 @@ import aiohttp
|
|
|
11
11
|
from .exceptions import (
|
|
12
12
|
GoogleWeatherApiAuthError,
|
|
13
13
|
GoogleWeatherApiConnectionError,
|
|
14
|
+
GoogleWeatherApiConnectionTimeoutError,
|
|
14
15
|
GoogleWeatherApiResponseError,
|
|
15
16
|
)
|
|
16
17
|
from .model import (
|
|
@@ -71,28 +72,33 @@ class GoogleWeatherApi:
|
|
|
71
72
|
headers=headers,
|
|
72
73
|
timeout=self.timeout,
|
|
73
74
|
) as resp:
|
|
74
|
-
res: dict[str, Any] = await resp.json()
|
|
75
75
|
_LOGGER.debug("Got %s for %s", resp.status, url)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
error_msg = error_data.get("message", "Unknown API error")
|
|
79
|
-
|
|
80
|
-
if resp.status in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
|
|
81
|
-
raise GoogleWeatherApiAuthError(error_msg)
|
|
82
|
-
|
|
83
|
-
# Google APIs often return 400 Bad Request for invalid API keys
|
|
84
|
-
if resp.status == HTTPStatus.BAD_REQUEST:
|
|
85
|
-
for detail in error_data.get("details", []):
|
|
86
|
-
if detail.get("reason") == "API_KEY_INVALID":
|
|
87
|
-
raise GoogleWeatherApiAuthError(error_msg)
|
|
88
|
-
|
|
89
|
-
raise GoogleWeatherApiResponseError(error_msg)
|
|
90
|
-
return res
|
|
76
|
+
status_code = resp.status
|
|
77
|
+
body = None if status_code == HTTPStatus.GATEWAY_TIMEOUT else await resp.json()
|
|
91
78
|
except TimeoutError as err:
|
|
92
|
-
raise
|
|
79
|
+
raise GoogleWeatherApiConnectionTimeoutError("Timeout") from err
|
|
93
80
|
except aiohttp.ClientError as err:
|
|
94
81
|
raise GoogleWeatherApiConnectionError(err) from err
|
|
95
82
|
|
|
83
|
+
if status_code == HTTPStatus.GATEWAY_TIMEOUT:
|
|
84
|
+
raise GoogleWeatherApiConnectionTimeoutError("Timeout")
|
|
85
|
+
res: dict[str, Any] = body if isinstance(body, dict) else {}
|
|
86
|
+
if status_code != HTTPStatus.OK:
|
|
87
|
+
error_data = res.get("error", {})
|
|
88
|
+
error_msg = error_data.get("message", "Unknown API error")
|
|
89
|
+
|
|
90
|
+
if status_code in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
|
|
91
|
+
raise GoogleWeatherApiAuthError(error_msg)
|
|
92
|
+
|
|
93
|
+
# Google APIs often return 400 Bad Request for invalid API keys
|
|
94
|
+
if status_code == HTTPStatus.BAD_REQUEST:
|
|
95
|
+
for detail in error_data.get("details", []):
|
|
96
|
+
if detail.get("reason") == "API_KEY_INVALID":
|
|
97
|
+
raise GoogleWeatherApiAuthError(error_msg)
|
|
98
|
+
|
|
99
|
+
raise GoogleWeatherApiResponseError(error_msg)
|
|
100
|
+
return res
|
|
101
|
+
|
|
96
102
|
async def _async_get_all_pages(
|
|
97
103
|
self,
|
|
98
104
|
endpoint: str,
|
google_weather_api/exceptions.py
CHANGED
|
@@ -9,6 +9,10 @@ class GoogleWeatherApiConnectionError(GoogleWeatherApiError):
|
|
|
9
9
|
"""Exception connecting to the Google Weather API."""
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
class GoogleWeatherApiConnectionTimeoutError(GoogleWeatherApiConnectionError, TimeoutError):
|
|
13
|
+
"""Exception raised when a request to the Google Weather API times out."""
|
|
14
|
+
|
|
15
|
+
|
|
12
16
|
class GoogleWeatherApiAuthError(GoogleWeatherApiError):
|
|
13
17
|
"""Exception raised for authentication errors in the Google Weather API."""
|
|
14
18
|
|
google_weather_api/model.py
CHANGED
|
@@ -42,6 +42,7 @@ class BaseModel(DataClassJSONMixin):
|
|
|
42
42
|
|
|
43
43
|
serialize_by_alias = True
|
|
44
44
|
allow_deserialization_not_by_alias = True
|
|
45
|
+
omit_none = True
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
@dataclass
|
|
@@ -523,12 +524,12 @@ class ForecastDay(BaseModel):
|
|
|
523
524
|
class DailyForecastResponse(BaseModel):
|
|
524
525
|
"""Response model for the forecast.days.lookup method."""
|
|
525
526
|
|
|
526
|
-
forecast_days: list[ForecastDay] = field(metadata={"alias": "forecastDays"})
|
|
527
|
-
"""The daily forecast records."""
|
|
528
|
-
|
|
529
527
|
time_zone: TimeZone = field(metadata={"alias": "timeZone"})
|
|
530
528
|
"""The time zone at the requested location."""
|
|
531
529
|
|
|
530
|
+
forecast_days: list[ForecastDay] = field(default_factory=list, metadata={"alias": "forecastDays"})
|
|
531
|
+
"""The daily forecast records."""
|
|
532
|
+
|
|
532
533
|
next_page_token: str | None = field(default=None, metadata={"alias": "nextPageToken"})
|
|
533
534
|
"""The token to retrieve the next page."""
|
|
534
535
|
|
|
@@ -631,12 +632,12 @@ class ForecastHour(BaseModel):
|
|
|
631
632
|
class HourlyForecastResponse(BaseModel):
|
|
632
633
|
"""Response model for the forecast.hours.lookup method."""
|
|
633
634
|
|
|
634
|
-
forecast_hours: list[ForecastHour] = field(metadata={"alias": "forecastHours"})
|
|
635
|
-
"""The hourly forecast records."""
|
|
636
|
-
|
|
637
635
|
time_zone: TimeZone = field(metadata={"alias": "timeZone"})
|
|
638
636
|
"""The time zone at the requested location."""
|
|
639
637
|
|
|
638
|
+
forecast_hours: list[ForecastHour] = field(default_factory=list, metadata={"alias": "forecastHours"})
|
|
639
|
+
"""The hourly forecast records."""
|
|
640
|
+
|
|
640
641
|
next_page_token: str | None = field(default=None, metadata={"alias": "nextPageToken"})
|
|
641
642
|
"""The token to retrieve the next page."""
|
|
642
643
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
google_weather_api/__init__.py,sha256=sOOI0Muwa4HERSM6W1OCtumAasjuV_7WkCFKEDm3T8c,1691
|
|
2
|
+
google_weather_api/api.py,sha256=K2G4kh7JN8E9h1HJ4EBDGKBd6DyoryTKyQ7qaZZmSNw,7707
|
|
3
|
+
google_weather_api/exceptions.py,sha256=z4rKXfRZLhkFLt1MISki1-nTxV_5Uc14ppjW7qu0ZNQ,708
|
|
4
|
+
google_weather_api/model.py,sha256=Mj7eOhu696KXFpuEEXxobQeMUG2aKDjO2D3lGPLugP0,24927
|
|
5
|
+
google_weather_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
python_google_weather_api-0.0.10.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
+
python_google_weather_api-0.0.10.dist-info/METADATA,sha256=KgAggQCD2_viCLkwk283XyosqwN2mOi00yRB2rOIay4,1413
|
|
8
|
+
python_google_weather_api-0.0.10.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
python_google_weather_api-0.0.10.dist-info/top_level.txt,sha256=ZkFbtKDHz3vUJhH6DGEPVLj3PPeNpR9-Wg0f4HqGD78,19
|
|
10
|
+
python_google_weather_api-0.0.10.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
google_weather_api/__init__.py,sha256=Su4PjNcbIJFYoFCEH4wwdtT-M2HSMtLNLvF-TWGHiNo,1601
|
|
2
|
-
google_weather_api/api.py,sha256=4_Y8TN6Mtrf4JDGoBOVm6W0uedxe5sPxMVx-ktD2kCI,7478
|
|
3
|
-
google_weather_api/exceptions.py,sha256=AHHzb-cbE0bgzp4PH2IC5s3jHAJHONbL9iw5b-_MvoU,534
|
|
4
|
-
google_weather_api/model.py,sha256=2Dx6VGh5Uaotb3McZSNs0BT6iJTrr5spYEUUC-IlXiA,24858
|
|
5
|
-
google_weather_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
python_google_weather_api-0.0.9.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
-
python_google_weather_api-0.0.9.dist-info/METADATA,sha256=SvCCnXAfToJfdwSvgBJ1D41y3lR3IsJGxgBwl_WJY5E,1412
|
|
8
|
-
python_google_weather_api-0.0.9.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
-
python_google_weather_api-0.0.9.dist-info/top_level.txt,sha256=ZkFbtKDHz3vUJhH6DGEPVLj3PPeNpR9-Wg0f4HqGD78,19
|
|
10
|
-
python_google_weather_api-0.0.9.dist-info/RECORD,,
|
{python_google_weather_api-0.0.9.dist-info → python_google_weather_api-0.0.10.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|