Added gitlab-ci, testing first automatic deployment

This commit is contained in:
Roger Gonzalez 2023-08-17 11:35:32 -03:00
parent e97d289e11
commit 2f68cf8907
Signed by: rogs
GPG Key ID: C7ECE9C6C36EC2E6
5 changed files with 19 additions and 31 deletions

7
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,7 @@
image: python:latest
run:
script:
- pip install build twine
- python -m build
- TWINE_PASSWORD=$PYPI_PASSWORD TWINE_USERNAME=$PYPI_USERNAME python3 -m twine upload --repository testpypi dist/*

View File

@ -45,16 +45,19 @@ build-backend = "hatchling.build"
[project]
name = "ute_wrapper"
version = "1.0.0"
version = "1.0.5"
authors = [
{ name="Roger Gonzalez", email="roger@rogs.me" },
]
description = "A wrapper to interact with UTE's API"
dependencies = [
"requests"
]
readme = "README.md"
requires-python = ">=3.7"
license = {file = "LICENSE"}
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

View File

@ -16,15 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os
from datetime import datetime, timedelta
from time import sleep
from typing import List, Optional
from dotenv import load_dotenv
from utils import get_average_price, make_request
load_dotenv()
from .utils import make_request
BASE_URL = "https://rocme.ute.com.uy/api/v1"
@ -50,7 +46,7 @@ def login(email: str, phone_number: str) -> str:
return make_request("POST", url, data=data).text
def get_ute_device_list() -> List[dict]:
def get_ute_device_list(authorization: str) -> List[dict]:
"""
Get UTE device list
@ -62,7 +58,7 @@ def get_ute_device_list() -> List[dict]:
return make_request("GET", accounts_url, authorization=authorization).json()["data"]
def get_ute_account_info(device_id: str) -> dict:
def get_ute_account_info(device_id: str, authorization: str) -> dict:
"""
Get UTE account info from device id
@ -77,7 +73,7 @@ def get_ute_account_info(device_id: str) -> dict:
return make_request("GET", accounts_by_id_url, authorization=authorization).json()["data"]
def get_ute_peak_info(device_id: str) -> dict:
def get_ute_peak_info(device_id: str, authorization: str) -> dict:
"""
Get UTE peak info from device id
@ -92,7 +88,7 @@ def get_ute_peak_info(device_id: str) -> dict:
return make_request("GET", peak_by_id_url, authorization=authorization).json()["data"]
def get_ute_network_status() -> dict:
def get_ute_network_status(authorization: str) -> dict:
"""
Get UTE network status from device id
@ -104,7 +100,7 @@ def get_ute_network_status() -> dict:
return make_request("GET", network_status_url, authorization=authorization).json()["data"]["summary"]
def get_ute_renewable_sources() -> str:
def get_ute_renewable_sources(authorization: str) -> str:
"""
Get UTE renewable sources
@ -119,6 +115,7 @@ def get_ute_renewable_sources() -> str:
def get_ute_historic_info(
device_id: str,
authorization: str,
average_price: float,
cost_per_kwh: float,
date_start: Optional[str] = None,
date_end: Optional[str] = None,
@ -229,22 +226,3 @@ def get_current_usage_info(device_id: str, authorization: str) -> dict:
return_dict["data"]["power_in_watts"] = power_in_watts
return return_dict
if __name__ == "__main__":
date_start = "2023-08-01"
date_end = "2023-08-31"
EMAIL = os.environ.get("EMAIL")
PHONE_NUMBER = os.environ.get("PHONE_NUMBER")
average_price = get_average_price("triple")
authorization = login(EMAIL, PHONE_NUMBER)
device_list = get_ute_device_list()
device_id = device_list[0]["accountServicePointId"]
account_info = get_ute_account_info(device_id)
peak_info = get_ute_peak_info(device_id)
network_status = get_ute_network_status()
renewable_sources = get_ute_renewable_sources()
ute_historic_usage = get_ute_historic_info(device_id, authorization, average_price, date_start, date_end)
ute_current_usage = get_current_usage_info(device_id, authorization)