Fix energy price retrieval to handle empty responses
This commit is contained in:
parent
4bd28614cc
commit
3a2b78fcce
1 changed files with 6 additions and 1 deletions
|
@ -33,7 +33,12 @@ def get_energy_prices(d: datetime.date=datetime.date.today(), no_cache:bool=Fals
|
||||||
|
|
||||||
if not hours or no_cache:
|
if not hours or no_cache:
|
||||||
r = requests.get(url_energy.format(date_str))
|
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:
|
if len(data) == 24:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue