From 81f155df4864d9b7caad0e511bb83347944f132d Mon Sep 17 00:00:00 2001 From: PacificDou Date: Mon, 18 Nov 2024 11:23:46 +0000 Subject: [PATCH 1/2] use local timezone --- roboflow/adapters/deploymentapi.py | 11 ++++++----- roboflow/deployment.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/roboflow/adapters/deploymentapi.py b/roboflow/adapters/deploymentapi.py index 1fef374..98e9347 100644 --- a/roboflow/adapters/deploymentapi.py +++ b/roboflow/adapters/deploymentapi.py @@ -1,5 +1,5 @@ import requests - +import urllib from roboflow.config import DEDICATED_DEPLOYMENT_URL @@ -58,13 +58,14 @@ def list_machine_types(api_key): def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None, max_entries=-1): - url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?api_key={api_key}&deployment_name={deployment_name}" + params = {'api_key': api_key, 'deployment_name': deployment_name} if from_timestamp is not None: - url += f"&from_timestamp={from_timestamp.isoformat()}" + params['from_timestamp'] = from_timestamp.isoformat() # may contain + sign if to_timestamp is not None: - url += f"&to_timestamp={to_timestamp.isoformat()}" + params['to_timestamp'] = to_timestamp.isoformat() # may contain + sign if max_entries > 0: - url += f"&max_entries={max_entries}" + params['max_entries'] = max_entries + url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?{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 97c77ff..d8f7523 100644 --- a/roboflow/deployment.py +++ b/roboflow/deployment.py @@ -169,7 +169,7 @@ def get_deployment_log(args): print("Please provide an api key") exit(1) - to_timestamp = datetime.now() + to_timestamp = datetime.now().astimezone() # local timezone from_timestamp = to_timestamp - timedelta(seconds=args.duration) last_log_timestamp = from_timestamp log_ids = set() # to avoid duplicate logs @@ -183,7 +183,7 @@ def get_deployment_log(args): exit(status_code) for log in msg[::-1]: # logs are sorted by reversed timestamp - log_timestamp = datetime.fromisoformat(log["timestamp"]).replace(tzinfo=None) + log_timestamp = datetime.fromisoformat(log["timestamp"]).astimezone() # local timezone if (log["insert_id"] in log_ids) or (log_timestamp < last_log_timestamp): continue log_ids.add(log["insert_id"]) @@ -195,5 +195,5 @@ def get_deployment_log(args): time.sleep(10) from_timestamp = last_log_timestamp - to_timestamp = datetime.now() + to_timestamp = datetime.now().astimezone() # local timezone max_entries = 300 # only set max_entries for the first request From 3c39c8bbe1029f2b670efd8b8d705ea51303bdbe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:26:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roboflow/adapters/deploymentapi.py | 12 +++++++----- roboflow/deployment.py | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/roboflow/adapters/deploymentapi.py b/roboflow/adapters/deploymentapi.py index 98e9347..a6420d9 100644 --- a/roboflow/adapters/deploymentapi.py +++ b/roboflow/adapters/deploymentapi.py @@ -1,5 +1,7 @@ -import requests import urllib + +import requests + from roboflow.config import DEDICATED_DEPLOYMENT_URL @@ -58,13 +60,13 @@ def list_machine_types(api_key): def get_deployment_log(api_key, deployment_name, from_timestamp=None, to_timestamp=None, max_entries=-1): - params = {'api_key': api_key, 'deployment_name': deployment_name} + params = {"api_key": api_key, "deployment_name": deployment_name} if from_timestamp is not None: - params['from_timestamp'] = from_timestamp.isoformat() # may contain + sign + params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign if to_timestamp is not None: - params['to_timestamp'] = to_timestamp.isoformat() # may contain + sign + params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign if max_entries > 0: - params['max_entries'] = max_entries + params["max_entries"] = max_entries url = f"{DEDICATED_DEPLOYMENT_URL}/get_log?{urllib.parse.urlencode(params)}" response = requests.get(url) if response.status_code != 200: diff --git a/roboflow/deployment.py b/roboflow/deployment.py index d8f7523..08530bc 100644 --- a/roboflow/deployment.py +++ b/roboflow/deployment.py @@ -169,7 +169,7 @@ def get_deployment_log(args): print("Please provide an api key") exit(1) - to_timestamp = datetime.now().astimezone() # local timezone + to_timestamp = datetime.now().astimezone() # local timezone from_timestamp = to_timestamp - timedelta(seconds=args.duration) last_log_timestamp = from_timestamp log_ids = set() # to avoid duplicate logs @@ -195,5 +195,5 @@ def get_deployment_log(args): time.sleep(10) from_timestamp = last_log_timestamp - to_timestamp = datetime.now().astimezone() # local timezone + to_timestamp = datetime.now().astimezone() # local timezone max_entries = 300 # only set max_entries for the first request