Added a function to get the average price for a given plan

This commit is contained in:
Roger Gonzalez 2023-08-17 08:48:32 -03:00
parent 53ff0738df
commit ac9045758d
Signed by: rogs
GPG Key ID: C7ECE9C6C36EC2E6
2 changed files with 23 additions and 1 deletions

View File

@ -6,6 +6,8 @@ from typing import Optional
import requests
from dotenv import load_dotenv
from utils import get_average_price
load_dotenv()
DEVICE_ID = os.environ.get("DEVICE_ID")
@ -189,7 +191,7 @@ def get_current_usage_info(device_id: str, authorization: str) -> dict:
if __name__ == "__main__":
date_start = "2023-08-01"
date_end = "2023-08-31"
average_price = (10.680 * 0.1667) + (2.223 * 0.2917) + (4.875 * 0.5416) # Each price * percentage of time on the day
average_price = get_average_price("triple")
authorization = login(EMAIL, PHONE_NUMBER)
ute_historic_usage = get_ute_historic_info(DEVICE_ID, authorization, average_price, date_start, date_end)

20
utils.py Normal file
View File

@ -0,0 +1,20 @@
def get_average_price(plan: str) -> float:
"""
Get the average price for a plan
Args:
plan (str): Plan name. Can be "triple" or "doble"
Returns:
float: Average price
Raises:
Exception: If the plan is invalid
"""
if plan == "triple":
return (10.680 * 0.1667) + (2.223 * 0.2917) + (4.875 * 0.5416)
if plan == "doble":
return (10.680 * 0.1667) + (4.280 * 0.8333)
raise Exception("Invalid plan")