diff --git a/src/pygenesis/cache.py b/src/pygenesis/cache.py index 04c642d..e08df06 100644 --- a/src/pygenesis/cache.py +++ b/src/pygenesis/cache.py @@ -75,9 +75,8 @@ def clean_cache(file: Optional[str]) -> None: ) # remove specified file (directory) from the data cache or clear complete cache - file_path = ( - cache_dir / cache_dir.glob(file) if file is not None else cache_dir - ) + # TODO: Find corresponding directories with cache_dir.glob(file) + file_path = cache_dir / file if file is not None else cache_dir try: if file_path.is_file() or file_path.is_symlink(): diff --git a/src/pygenesis/destatis.py b/src/pygenesis/destatis.py index e17b4f3..f61d608 100644 --- a/src/pygenesis/destatis.py +++ b/src/pygenesis/destatis.py @@ -1,11 +1,13 @@ """Module provides functions to work with the GENESIS REST-API.""" +from typing import Any + from pygenesis.config import load_config from pygenesis.http_helper import get_response_from_endpoint config = load_config() -def get_metadata(endpoint: str, name: str) -> str: +def get_metadata(endpoint: str, name: str) -> Any: """Method for downloading metadata from www-genesis.destatis.de. Method supports the following endpoints: @@ -21,16 +23,16 @@ def get_metadata(endpoint: str, name: str) -> str: name (str): Unique name of the object. Returns: - str: Content of "Object" response. + Any: JSON formatted content of "Object" response. """ params = { "name": name, } - return get_response_from_endpoint("metadata", endpoint, params).text + return get_response_from_endpoint("metadata", endpoint, params).json() -def get_catalogue(endpoint: str, params: dict) -> dict: +def get_catalogue(endpoint: str, params: dict) -> Any: """Method for downloading catalogue data from www-genesis.destatis.de. Args: @@ -38,20 +40,20 @@ def get_catalogue(endpoint: str, params: dict) -> dict: params (dict): The query parameter as defined by the API. Returns: - dict: JSON formated response for the given query parameters. + Any: JSON formated response for the given query parameters. """ return get_response_from_endpoint("catalogue", endpoint, params).json() -def get_cubefile(params: dict) -> str: +def get_cubefile(params: dict) -> Any: """Method for downloading cube files from www-genesis.destatis.de. Args: params (dict): The query parameter as defined by the API. Returns: - str: The content of the cubefile. + Any: The content of the cubefile. """ return get_response_from_endpoint("data", "cubefile", params).text diff --git a/src/pygenesis/http_helper.py b/src/pygenesis/http_helper.py index 190b53c..039425a 100644 --- a/src/pygenesis/http_helper.py +++ b/src/pygenesis/http_helper.py @@ -101,9 +101,9 @@ def _check_destatis_status(destatis_status: dict) -> None: ValueError: If the status code or type displays an error (caused by the user inputs) """ # -1 status code for unexpected errors and if no status code is given (faulty response) - destatis_status_code = destatis_status.get("Code", -1) - destatis_status_type = destatis_status.get("Type") - destatis_status_content = destatis_status.get("Content") + destatis_status_code = int(destatis_status.get("Code", -1)) + destatis_status_type = str(destatis_status.get("Type", "Information")) + destatis_status_content = str(destatis_status.get("Content")) # define status types error_en_de = ["Error", "Fehler"]