diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 82911d3..b18fdf4 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -54,36 +54,36 @@ jobs: run: | pytest tests/test_cached_api.py --doctest-modules --junitxml=tests/cached-api-test-results.xml - name: Upload cached API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: cached-api-test-results + name: cached-api-test-results-${{matrix.python-version}} path: tests/cached-api-test-results.xml - name: Test Wolfram API run: | pytest tests/test_wolfram_api.py --doctest-modules --junitxml=tests/wolfram-api-test-results.xml - name: Upload Wolfram API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: wolfram-api-test-results + name: wolfram-api-test-results-${{matrix.python-version}} path: tests/wolfram-api-test-results.xml - name: Test Alpha Vantage API run: | pytest tests/test_alpha_vantage_api.py --doctest-modules --junitxml=tests/alphavantage-api-test-results.xml - name: Upload Alpha Vantage API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: alphavantage-api-test-results + name: alphavantage-api-test-results-${{matrix.python-version}} path: tests/alphavantage-api-test-results.xml - name: Test OWM API run: | pytest tests/test_owm_api.py --doctest-modules --junitxml=tests/owm-api-test-results.xml - name: Upload Open Weather Map API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: owm-api-test-results + name: owm-api-test-results-${{matrix.python-version}} path: tests/owm-api-test-results.xml - name: Test Map Maker API @@ -92,16 +92,16 @@ jobs: env: MAP_MAKER_KEY: ${{secrets.map_maker_key}} - name: Upload Map Maker API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: map-maker-api-test-results + name: map-maker-api-test-results-${{matrix.python-version}} path: tests/map-maker-api-test-results.xml - name: Test Generic API run: | pytest tests/test_generic_controller.py --doctest-modules --junitxml=tests/generic-controller-test-results.xml - name: Upload Generic API test results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: generic-controller-test-results + name: generic-controller-test-results-${{matrix.python-version}} path: tests/generic-controller-test-results.xml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d4f2d8..9475a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,37 +1,20 @@ # Changelog -## [0.6.0](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.6.0) (2024-06-17) +## [0.6.1a2](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.6.1a2) (2024-09-12) -[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a3...0.6.0) - -**Implemented enhancements:** - -- \[FEAT\] Add Daily and Hourly Weather API calls [\#71](https://github.com/NeonGeckoCom/neon_api_proxy/issues/71) -- Handle requests for unauthenticated APIs [\#21](https://github.com/NeonGeckoCom/neon_api_proxy/issues/21) - -## [0.5.1a3](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a3) (2024-05-07) - -[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a2...0.5.1a3) - -**Merged pull requests:** - -- Update W|A and OWM wrappers to match upstream APIs [\#96](https://github.com/NeonGeckoCom/neon_api_proxy/pull/96) ([NeonDaniel](https://github.com/NeonDaniel)) - -## [0.5.1a2](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a2) (2024-04-25) - -[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.1a1...0.5.1a2) +[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.6.1a1...0.6.1a2) **Merged pull requests:** -- feat: allow ovos-utils 0.1.0 [\#94](https://github.com/NeonGeckoCom/neon_api_proxy/pull/94) ([mikejgray](https://github.com/mikejgray)) +- Update configuration handling [\#99](https://github.com/NeonGeckoCom/neon_api_proxy/pull/99) ([NeonDaniel](https://github.com/NeonDaniel)) -## [0.5.1a1](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.5.1a1) (2024-04-09) +## [0.6.1a1](https://github.com/NeonGeckoCom/neon_api_proxy/tree/0.6.1a1) (2024-08-08) -[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.5.0...0.5.1a1) +[Full Changelog](https://github.com/NeonGeckoCom/neon_api_proxy/compare/0.6.0...0.6.1a1) **Merged pull requests:** -- OWM language handling [\#93](https://github.com/NeonGeckoCom/neon_api_proxy/pull/93) ([NeonDaniel](https://github.com/NeonDaniel)) +- Refactor backend services to accept more configuration params in init [\#98](https://github.com/NeonGeckoCom/neon_api_proxy/pull/98) ([NeonDaniel](https://github.com/NeonDaniel)) diff --git a/neon_api_proxy/controller.py b/neon_api_proxy/controller.py index 172e4cd..8f6f560 100644 --- a/neon_api_proxy/controller.py +++ b/neon_api_proxy/controller.py @@ -27,7 +27,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from os.path import join, isfile -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation from ovos_config.config import Configuration from neon_utils.configuration_utils import NGIConfig from ovos_config.locations import get_xdg_config_save_path @@ -70,10 +70,16 @@ def _init_config() -> dict: legacy_config_file = join(get_xdg_config_save_path(), "ngi_auth_vars.yml") if isfile(legacy_config_file): - LOG.warning(f"Legacy configuration found at: {legacy_config_file}") - return NGIConfig("ngi_auth_vars").get("api_services", {}) + log_deprecation(f"Legacy configuration found at: {legacy_config_file}. " + f"This will be ignored in future versions. " + f"Default configuration handling will use " + f"~/.config/neon/diana.yaml.", + "1.0.0") + return NGIConfig("ngi_auth_vars").get("api_services") or dict() else: - return Configuration().get("keys", {}).get("api_services", {}) + config = Configuration() + return config.get("keys", {}).get("api_services") or \ + config.get("api_services") or dict() def init_service_instances(self, service_class_mapping: dict) -> dict: """ @@ -86,14 +92,14 @@ def init_service_instances(self, service_class_mapping: dict) -> dict: """ service_mapping = dict() for item in service_class_mapping: - api_key = self.config.get(item, {}).get("api_key") if self.config \ - else None + service_config = self.config.get(item) or dict() try: - if api_key is None and item != 'api_test_endpoint': + if service_config.get("api_key") is None and item not in \ + ('api_test_endpoint', "ip_api"): LOG.warning(f"No API key for {item} in " f"{list(self.config.keys())}") service_mapping[item] = \ - service_class_mapping[item](api_key=api_key) + service_class_mapping[item](**service_config) except Exception as e: LOG.error(e) return service_mapping diff --git a/neon_api_proxy/services/alpha_vantage_api.py b/neon_api_proxy/services/alpha_vantage_api.py index 4549967..f4cb4c9 100644 --- a/neon_api_proxy/services/alpha_vantage_api.py +++ b/neon_api_proxy/services/alpha_vantage_api.py @@ -48,10 +48,10 @@ class AlphaVantageAPI(CachedAPI): API for querying Alpha Vantage. """ - def __init__(self, api_key: str = None): + def __init__(self, api_key: str = None, cache_seconds: int = 300, **_): super().__init__("alpha_vantage") self._api_key = api_key or find_neon_alpha_vantage_key() - self.quote_timeout = timedelta(minutes=5) + self.quote_timeout = timedelta(seconds=cache_seconds) def _search_symbol(self, query: str) -> dict: if not query: diff --git a/neon_api_proxy/services/map_maker_api.py b/neon_api_proxy/services/map_maker_api.py index 96dc404..13dad14 100644 --- a/neon_api_proxy/services/map_maker_api.py +++ b/neon_api_proxy/services/map_maker_api.py @@ -42,7 +42,7 @@ class MapMakerAPI(CachedAPI): API for querying My Maps API (geocoder.maps.co). """ - def __init__(self, api_key: str = None, cache_seconds=604800): # Cache week + def __init__(self, api_key: str = None, cache_seconds: int = 604800, **_): # Cache week super().__init__("map_maker") self._api_key = api_key or getenv("MAP_MAKER_KEY") if not self._api_key: diff --git a/neon_api_proxy/services/owm_api.py b/neon_api_proxy/services/owm_api.py index f25fa30..dc915ff 100644 --- a/neon_api_proxy/services/owm_api.py +++ b/neon_api_proxy/services/owm_api.py @@ -41,7 +41,7 @@ class OpenWeatherAPI(CachedAPI): API for querying Open Weather Map. """ - def __init__(self, api_key: str = None, cache_seconds=180): + def __init__(self, api_key: str = None, cache_seconds: int = 900, **_): super().__init__("open_weather_map") self._api_key = api_key or find_neon_owm_key() self.cache_timeout = timedelta(seconds=cache_seconds) diff --git a/neon_api_proxy/services/test_api.py b/neon_api_proxy/services/test_api.py index 1e118b4..14af156 100644 --- a/neon_api_proxy/services/test_api.py +++ b/neon_api_proxy/services/test_api.py @@ -30,7 +30,7 @@ class TestAPI(CachedAPI): - def __init__(self, api_key: str = None): + def __init__(self, api_key: str = None, **_): super().__init__("Test") def handle_query(self, **kwargs) -> dict: diff --git a/neon_api_proxy/services/wolfram_api.py b/neon_api_proxy/services/wolfram_api.py index 175c536..518d7cc 100644 --- a/neon_api_proxy/services/wolfram_api.py +++ b/neon_api_proxy/services/wolfram_api.py @@ -51,11 +51,11 @@ class WolframAPI(CachedAPI): API for querying Wolfram|Alpha. """ - def __init__(self, api_key: str = None): + def __init__(self, api_key: str = None, cache_seconds: int = 3600, **_): super().__init__("wolfram") self._api_key = api_key or find_neon_wolfram_key() self.session.allowable_codes = (200, 501) - self.cache_time = timedelta(minutes=60) + self.cache_time = timedelta(seconds=cache_seconds) def _build_query_url(self, query_type: QueryUrl, query_arg: str) -> str: """ diff --git a/version.py b/version.py index b425a5e..93da92a 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "0.6.0" +__version__ = "0.7.0"