diff --git a/calculator/main.py b/calculator/main.py index 4423cd9..53adba8 100644 --- a/calculator/main.py +++ b/calculator/main.py @@ -1,6 +1,6 @@ import datetime import calendar -from typing import List +from typing import List, Optional from fastapi import FastAPI, HTTPException from fastapi.responses import RedirectResponse @@ -70,9 +70,9 @@ rest: @app.get("/price/day", description=docs) @app.get("/price/day/{date}", description=docs) def read_item( - date: datetime.date=datetime.date.today(), - hour:int=datetime.datetime.now().hour, - monthly_fees: float = 509.24, + date: Optional[datetime.date]=None, + hour: Optional[int]=None, + monthly_fees: float=509.24, daily_fees: float=4.18, kwh_fees_low: float=1.62421, kwh_fees_high: float=1.83474, @@ -82,6 +82,11 @@ def read_item( num_cheapest_hours:int = 8, ) -> DayPrice: + if not date: + date = datetime.date.today() + if not hour: + hour = datetime.datetime.now().hour + is_today = datetime.date.today() == date low_tariff_hours_parsed = [int(x.strip()) for x in low_tariff_hours.split(",")]