From 84e5b54837c943fb16cc0c6f93f25847cc40c50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Thu, 8 Aug 2024 11:02:21 +0200 Subject: [PATCH] Fix default values --- calculator/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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(",")]