diff options
author | Roger Gonzalez <roger@rogs.me> | 2023-08-17 10:34:03 -0300 |
---|---|---|
committer | Roger Gonzalez <roger@rogs.me> | 2023-08-17 10:34:03 -0300 |
commit | 345beaa975d46a36db0514cd75249605cfb95686 (patch) | |
tree | e590e32c6b10f3df1a8fc321af1c3e24326a2cbb | |
parent | 7f8f3e19c7d96ca88605f73d57814369291b7728 (diff) |
Abstracted the base_url from the URLs
-rwxr-xr-x | script.py | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -9,6 +9,8 @@ from utils import get_average_price, make_request load_dotenv() +BASE_URL = "https://rocme.ute.com.uy/api/v1" + def login(email: str, phone_number: str) -> str: """ @@ -22,7 +24,7 @@ def login(email: str, phone_number: str) -> str: str: Authorization token """ - url = "https://rocme.ute.com.uy/api/v1/token" + url = f"{BASE_URL}/token" data = { "Email": email, "PhoneNumber": phone_number, @@ -39,7 +41,8 @@ def get_ute_device_list() -> List[dict]: List[dict]: List of devices """ - return make_request("GET", "https://rocme.ute.com.uy/api/v1/accounts", authorization=authorization).json()["data"] + accounts_url = f"{BASE_URL}/accounts" + return make_request("GET", accounts_url, authorization=authorization).json()["data"] def get_ute_account_info(device_id: str) -> dict: @@ -53,9 +56,8 @@ def get_ute_account_info(device_id: str) -> dict: dict: UTE account info """ - return make_request( - "GET", f"https://rocme.ute.com.uy/api/v1/accounts/{device_id}", authorization=authorization - ).json()["data"] + accounts_by_id_url = f"{BASE_URL}/accounts/{device_id}" + return make_request("GET", accounts_by_id_url, authorization=authorization).json()["data"] def get_ute_peak_info(device_id: str) -> dict: @@ -69,9 +71,8 @@ def get_ute_peak_info(device_id: str) -> dict: dict: UTE peak info """ - return make_request( - "GET", f"https://rocme.ute.com.uy/api/v1/accounts/{device_id}/peak", authorization=authorization - ).json()["data"] + peak_by_id_url = f"{BASE_URL}/accounts/{device_id}/peak" + return make_request("GET", peak_by_id_url, authorization=authorization).json()["data"] def get_ute_network_status() -> dict: @@ -82,9 +83,8 @@ def get_ute_network_status() -> dict: dict: UTE network status """ - return make_request( - "GET", "https://rocme.ute.com.uy/api/v1/info/network/status", authorization=authorization - ).json()["data"]["summary"] + network_status_url = f"{BASE_URL}/info/network/status" + return make_request("GET", network_status_url, authorization=authorization).json()["data"]["summary"] def get_ute_renewable_sources() -> str: @@ -95,7 +95,8 @@ def get_ute_renewable_sources() -> str: str: UTE renewable sources percentage """ - return make_request("GET", "https://rocme.ute.com.uy/api/v1/info/demand/global").json()["data"]["renewableSources"] + global_demand_url = f"{BASE_URL}/info/demand/global" + return make_request("GET", global_demand_url).json()["data"]["renewableSources"] def get_ute_historic_info( @@ -127,9 +128,9 @@ def get_ute_historic_info( yesterday = datetime.now() - timedelta(days=1) date_end = yesterday.strftime("%Y-%m-%d") - url = f"https://rocme.ute.com.uy/api/v2/device/{device_id}/curvefromtodate/D/{date_start}/{date_end}" + historic_url = f"https://rocme.ute.com.uy/api/v2/device/{device_id}/curvefromtodate/D/{date_start}/{date_end}" - response = make_request("GET", url, authorization=authorization).json() + response = make_request("GET", historic_url, authorization=authorization).json() active_energy = {"total": {"sum_in_kwh": 0}} @@ -168,8 +169,8 @@ def get_current_usage_info(device_id: str, authorization: str) -> dict: Exception: If the reading request fails """ - reading_request_url = "https://rocme.ute.com.uy/api/v1/device/readingRequest" - reading_url = f"https://rocme.ute.com.uy/api/v1/device/{device_id}/lastReading/30" + reading_request_url = f"{BASE_URL}/device/readingRequest" + reading_url = f"{BASE_URL}/device/{device_id}/lastReading/30" data = {"AccountServicePointId": device_id} |