@@ -44,15 +44,25 @@ def list_deployment(api_key):
4444
4545
4646def get_workspace_usage (api_key , from_timestamp , to_timestamp ):
47- 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 )} "
4853 response = requests .get (url )
4954 if response .status_code != 200 :
5055 return response .status_code , response .text
5156 return response .status_code , response .json ()
5257
5358
5459def get_deployment_usage (api_key , deployment_name , from_timestamp , to_timestamp ):
55- 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 )} "
5666 response = requests .get (url )
5767 if response .status_code != 200 :
5868 return response .status_code , response .text
0 commit comments