From 3eee5b3f6954895bab19605442d879fee430dae2 Mon Sep 17 00:00:00 2001 From: PacificDou Date: Tue, 26 Nov 2024 11:03:30 +0000 Subject: [PATCH] set local timezone --- roboflow/adapters/deploymentapi.py | 14 ++++++++++++-- roboflow/deployment.py | 10 +++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/roboflow/adapters/deploymentapi.py b/roboflow/adapters/deploymentapi.py index 7735e02f..a63b0643 100644 --- a/roboflow/adapters/deploymentapi.py +++ b/roboflow/adapters/deploymentapi.py @@ -44,7 +44,12 @@ def list_deployment(api_key): def get_workspace_usage(api_key, from_timestamp, to_timestamp): - url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?api_key={api_key}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}" + params = {"api_key": api_key} + if from_timestamp is not None: + params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign + if to_timestamp is not None: + params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign + url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?{urllib.parse.urlencode(params)}" response = requests.get(url) if response.status_code != 200: return response.status_code, response.text @@ -52,7 +57,12 @@ def get_workspace_usage(api_key, from_timestamp, to_timestamp): def get_deployment_usage(api_key, deployment_name, from_timestamp, to_timestamp): - url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?api_key={api_key}&deployment_name={deployment_name}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}" + params = {"api_key": api_key, "deployment_name": deployment_name} + if from_timestamp is not None: + params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign + if to_timestamp is not None: + params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign + url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?{urllib.parse.urlencode(params)}" response = requests.get(url) if response.status_code != 200: return response.status_code, response.text diff --git a/roboflow/deployment.py b/roboflow/deployment.py index 1bb4b831..61d9454e 100644 --- a/roboflow/deployment.py +++ b/roboflow/deployment.py @@ -23,19 +23,19 @@ def check_from_to_timestamp(from_timestamp, to_timestamp, default_timedelta): print("Please provide a valid to_timestamp in ISO8601 format") exit(1) - time_now = datetime.now().replace(tzinfo=None) + time_now = datetime.now().astimezone() # local timezone if from_timestamp is None and to_timestamp is None: from_timestamp = time_now - default_timedelta to_timestamp = time_now elif from_timestamp is not None and to_timestamp is None: - from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None) + from_timestamp = datetime.fromisoformat(from_timestamp).astimezone() to_timestamp = from_timestamp + default_timedelta elif from_timestamp is None and to_timestamp is not None: - to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None) + to_timestamp = datetime.fromisoformat(to_timestamp).astimezone() from_timestamp = to_timestamp - default_timedelta else: - from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None) - to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None) + from_timestamp = datetime.fromisoformat(from_timestamp).astimezone() + to_timestamp = datetime.fromisoformat(to_timestamp).astimezone() if from_timestamp >= to_timestamp: print("from_timestamp should be earlier than to_timestamp") exit(1)