diff --git a/onboardapis/__init__.py b/onboardapis/__init__.py index 352b67b..9dca9f2 100644 --- a/onboardapis/__init__.py +++ b/onboardapis/__init__.py @@ -4,11 +4,11 @@ __project_name__ = 'onboardapis' __description__ = 'A pure Python wrapper for the on-board APIs of many different transportation providers' -__version__ = '1.3.1' +__version__ = '1.3.2' __author__ = 'Felix Zenk' __email__ = 'felix.zenk@web.de' __license__ = 'MIT' -__copyright__ = 'Copyright (c) 2022 Felix Zenk' +__copyright__ = 'Copyright (c) 2024 Felix Zenk' __url__ = 'https://github.com/felix-zenk/onboardapis' from abc import ABCMeta diff --git a/onboardapis/utils/data.py b/onboardapis/utils/data.py index ffdbf66..1ee244d 100644 --- a/onboardapis/utils/data.py +++ b/onboardapis/utils/data.py @@ -1,6 +1,7 @@ """ This module contains everything that has to do with data and data management """ +from __future__ import annotations import abc import json @@ -14,9 +15,11 @@ from requests import Response, RequestException from .conversions import coordinates_decimal_to_dms -from ..exceptions import DataInvalidError, APIConnectionError, InitialConnectionError +from ..exceptions import APIConnectionError, InitialConnectionError from .. import __version__ +logger = logging.getLogger(__name__) + def some_or_default(data: Optional[Any], default: Optional[Any] = None) -> Optional[Any]: """ @@ -274,7 +277,7 @@ def _get(self, endpoint: str, *args: Any, base_url: str = None, **kwargs: Any) - response = self._session.get(f"https://{base_url}{endpoint}", *args, **kwargs) # Report possible errors / changes in the API if response.status_code != 200: - logging.warning(f"Request to https://{base_url}{endpoint} returned status code {response.status_code}") + logger.warning(f"Request to https://{base_url}{endpoint} returned status code {response.status_code}") self._retries = 0 return response except RequestException as e: @@ -283,7 +286,7 @@ def _get(self, endpoint: str, *args: Any, base_url: str = None, **kwargs: Any) - raise APIConnectionError() from e # Retry the request if it failed self._retries += 1 - logging.debug(f"Request to https://{base_url}{endpoint} failed! Retry: ({self._retries}/2)") + logger.debug(f"Request to https://{base_url}{endpoint} failed! Retry: ({self._retries}/2)") return self._get(endpoint, *args, base_url=base_url, **kwargs) def load(self, key: str, __default: Any = None) -> Any: @@ -449,7 +452,7 @@ class JSONDataConnector(DataConnector, metaclass=abc.ABCMeta): __slots__ = [] - def _get(self, endpoint: str, *args: Any, base_url: str = None, **kwargs: Any) -> dict: + def _get(self, endpoint: str, *args: Any, base_url: str = None, **kwargs: Any) -> dict | None: headers = kwargs.get("headers", {}) headers.update({ "accept": "application/json", @@ -458,8 +461,8 @@ def _get(self, endpoint: str, *args: Any, base_url: str = None, **kwargs: Any) - try: return super(JSONDataConnector, self)._get(endpoint, *args, base_url=base_url, **kwargs).json() except json.JSONDecodeError as e: - logging.debug(f"Failed to parse json ({e.__class__.__name__}): {'; '.join(e.args)}") - raise DataInvalidError() from e + logger.warning(f"Failed to parse json ({e.__class__.__name__}): {'; '.join(e.args)}") + return None def export(self, path: Union[str, PathLike], keys: Sequence = None) -> None: """