1+ import urllib
2+
13import requests
24
35from roboflow .config import DEDICATED_DEPLOYMENT_URL
@@ -42,15 +44,25 @@ def list_deployment(api_key):
4244
4345
4446def get_workspace_usage (api_key , from_timestamp , to_timestamp ):
45- url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?api_key={ api_key } &from_timestamp={ from_timestamp .isoformat ()} &to_timestamp={ to_timestamp .isoformat ()} "
47+ params = {"api_key" : api_key }
48+ if from_timestamp is not None :
49+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
50+ if to_timestamp is not None :
51+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
52+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?{ urllib .parse .urlencode (params )} "
4653 response = requests .get (url )
4754 if response .status_code != 200 :
4855 return response .status_code , response .text
4956 return response .status_code , response .json ()
5057
5158
5259def get_deployment_usage (api_key , deployment_name , from_timestamp , to_timestamp ):
53- 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 ()} "
60+ params = {"api_key" : api_key , "deployment_name" : deployment_name }
61+ if from_timestamp is not None :
62+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
63+ if to_timestamp is not None :
64+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
65+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_deployment?{ urllib .parse .urlencode (params )} "
5466 response = requests .get (url )
5567 if response .status_code != 200 :
5668 return response .status_code , response .text
@@ -74,13 +86,14 @@ def list_machine_types(api_key):
7486
7587
7688def get_deployment_log (api_key , deployment_name , from_timestamp = None , to_timestamp = None , max_entries = - 1 ):
77- url = f" { DEDICATED_DEPLOYMENT_URL } /get_log? api_key= { api_key } & deployment_name= { deployment_name } "
89+ params = { " api_key" : api_key , " deployment_name" : deployment_name }
7890 if from_timestamp is not None :
79- url += f"& from_timestamp= { from_timestamp .isoformat ()} "
91+ params [ "from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
8092 if to_timestamp is not None :
81- url += f"& to_timestamp= { to_timestamp .isoformat ()} "
93+ params [ "to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
8294 if max_entries > 0 :
83- url += f"&max_entries={ max_entries } "
95+ params ["max_entries" ] = max_entries
96+ url = f"{ DEDICATED_DEPLOYMENT_URL } /get_log?{ urllib .parse .urlencode (params )} "
8497 response = requests .get (url )
8598 if response .status_code != 200 :
8699 return response .status_code , response .text
0 commit comments