From 3a2b78fcce4bbb4b8c21a65d6423f099971f87a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Fri, 3 Oct 2025 08:46:46 +0200 Subject: [PATCH] Fix energy price retrieval to handle empty responses --- calculator/miner.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/calculator/miner.py b/calculator/miner.py index 048b7e9..4a4c1d3 100644 --- a/calculator/miner.py +++ b/calculator/miner.py @@ -33,8 +33,13 @@ def get_energy_prices(d: datetime.date=datetime.date.today(), no_cache:bool=Fals if not hours or no_cache: r = requests.get(url_energy.format(date_str)) - data = r.json()["data"]["dataLine"][1]["point"] + resp = r.json()["data"]["dataLine"] + if len(resp) == 0: + raise PriceNotFound() + + data = resp[1]["point"] + if len(data) == 24: try: for raw in data: