Skip to content

Commit 3deff61

Browse files
Adjust getting date of data
1 parent 2f4f556 commit 3deff61

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

custom_components/tge/connector.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,20 @@ def get_data_for_date(date: datetime.date) -> TgeDayData | None:
9797

9898
@staticmethod
9999
def _get_date_of_data(html_parser: Tag) -> datetime.date:
100-
date_text = html_parser.select("body")[0].select("section")[4].select("small")[0].text.strip().replace(
101-
"dla dostawy w dniu ", "")
102-
date = datetime.datetime.strptime(date_text, "%d-%m-%Y").date()
100+
date_texts = list(filter(lambda l: len(l) > 0,
101+
map(lambda ft: re.findall(r"\d{2}-\d{2}-\d{4}", ft),
102+
filter(lambda t: "godzinowe" in t,
103+
map(lambda h: h.get_text(strip=True),
104+
parser.select(".kontrakt-date")
105+
)
106+
)
107+
)
108+
)
109+
)
110+
if len(date_texts) == 0:
111+
_LOGGER.error("No date of data found")
112+
raise TgeException("No date of data found")
113+
date = datetime.datetime.strptime(date_texts[0][0], "%d-%m-%Y").date()
103114
return date
104115

105116
@staticmethod

0 commit comments

Comments
 (0)