From b21cce8399d68bca342605941889ff70cde272fe Mon Sep 17 00:00:00 2001 From: Chris Pastl <christoph.pastl@fro.at> Date: Mon, 17 Jun 2024 23:14:53 +0200 Subject: [PATCH] chore: fetch virtual timeslots, add optional get params --- src/aura_engine/base/api.py | 10 ++++++---- src/aura_engine/scheduling/api.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/aura_engine/base/api.py b/src/aura_engine/base/api.py index 06b74825..b2de406f 100644 --- a/src/aura_engine/base/api.py +++ b/src/aura_engine/base/api.py @@ -204,7 +204,9 @@ class SimpleRestApi: return json_data @exception_handler - def get(self, url: str, headers: dict = None, timeout: int = 5) -> requests.Response: + def get( + self, url: str, headers: dict = None, params: dict = None, timeout: int = 5 + ) -> requests.Response: """ GET from an URL. @@ -222,7 +224,7 @@ class SimpleRestApi: json_data = None if not headers: headers = SimpleRestApi.default_headers - response = requests.get(url, headers=headers, timeout=timeout) + response = requests.get(url, headers=headers, params=params, timeout=timeout) if headers.get("content-type") == SimpleRestApi.CONTENT_JSON: json_data = self.deserialize_json(response) return DotDict({"response": response, "json": json_data}) @@ -305,7 +307,7 @@ class SimpleCachedRestApi: self.cache_location = cache_location self.logger = logging.getLogger(logger_name) - def get(self, url: str, headers: dict = None) -> requests.Response: + def get(self, url: str, headers: dict = None, params: dict = None) -> requests.Response: """ GET from an URL while also storing the result in the local cache. @@ -322,7 +324,7 @@ class SimpleCachedRestApi: """ filename = self.build_filename(url) cache_filepath = self.cache_location + filename - result = self.simple_api.get(url, headers) + result = self.simple_api.get(url, headers, params) if result and result.json and result.response.status_code == 200: with open(cache_filepath, "w") as file: diff --git a/src/aura_engine/scheduling/api.py b/src/aura_engine/scheduling/api.py index aa740bf1..d5190ce0 100644 --- a/src/aura_engine/scheduling/api.py +++ b/src/aura_engine/scheduling/api.py @@ -160,7 +160,7 @@ class ApiFetcher(threading.Thread): api_timeslots = None url = self.url_api_timeslots self.logger.debug("Fetch timeslots from Steering API...") - result = self.api.get(url) + result = self.api.get(url, params={"includeVirtual": "true"}) api_timeslots = result.json if not api_timeslots: return -- GitLab