Fixed List typing issue for older verions

This commit is contained in:
2023-05-19 19:10:30 +02:00
parent 8bbfd28fd4
commit 6958357296
3 changed files with 18 additions and 17 deletions

View File

@@ -1,9 +1,10 @@
import json
from datetime import date, datetime, timedelta
from typing import List
import requests
date_format = '%Y-%m-%dT%H:%M:%S%z'
date_format = "%Y-%m-%dT%H:%M:%S%z"
class EngieAPI:
@@ -18,10 +19,10 @@ class EngieAPI:
"User-Agent": "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36",
"Referer": "https://engieenergy.azurewebsites.net/",
"Content-Length": "294",
"Accept-Language": "en-GB,en;q=0.9"
"Accept-Language": "en-GB,en;q=0.9",
}
def get_epex_spot(self, date: date) -> list[float]:
def get_epex_spot(self, date: date) -> List[float]:
to_date = datetime(date.year, date.month, date.day, 23, 59, 59)
from_date = to_date - timedelta(days=1, hours=23, minutes=59, seconds=59)
@@ -29,14 +30,10 @@ class EngieAPI:
"ApplicationDate": {
"From": from_date.strftime(date_format),
"To": to_date.strftime(date_format),
"UseTime": True
"UseTime": True,
},
"IncludeOffset": True,
"Items": [
{
"IdRef": 7070
}
]
"Items": [{"IdRef": 7070}],
}
res = requests.post(self.url, headers=self.headers, data=json.dumps(data))
@@ -46,7 +43,7 @@ class EngieAPI:
# check if the Date is the same as the one requested, attention to the timezone
if datetime.strptime(j["Date"], date_format).date() == date:
values.append(j["Value"])
if not values:
raise ValueError("No data found for this date")
return values