From 83d01bb64c32c3489ba52406c90db599673f2026 Mon Sep 17 00:00:00 2001 From: stephan192 Date: Tue, 9 Dec 2025 20:30:25 +0100 Subject: [PATCH] Fix TH pegel page scraping --- CHANGELOG.md | 4 ++++ docs/update_pegel_list.py | 2 +- pyproject.toml | 2 +- src/lhpapi/th_api.py | 12 ++++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab406c2..ac96318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.8 (2025-12-09) +### Fixed +- Fix TH pegel page scraping + ## 1.0.7 (2025-11-23) ### Fixed - Fix HE without flow diff --git a/docs/update_pegel_list.py b/docs/update_pegel_list.py index 571e2e3..d54466b 100644 --- a/docs/update_pegel_list.py +++ b/docs/update_pegel_list.py @@ -411,7 +411,7 @@ def get_th_stations() -> tuple[str, str]: trs = tbody.find_all("tr") for row in trs: tds = row.find_all("td") - if len(tds) > 10: + if len(tds) > 3: ident = "TH_" + tds[1].getText().strip() name = tds[2].getText().strip() + " / " + tds[3].getText().strip() stations.append((ident, name)) diff --git a/pyproject.toml b/pyproject.toml index 67d2f60..3ab19d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "lhpapi" -version = "1.0.7" +version = "1.0.8" authors = [ { name="stephan192", email="stephan192@outlook.com" }, ] diff --git a/src/lhpapi/th_api.py b/src/lhpapi/th_api.py index f23daed..50f1954 100644 --- a/src/lhpapi/th_api.py +++ b/src/lhpapi/th_api.py @@ -23,7 +23,7 @@ def init_TH(ident: str) -> StaticData: # pylint: disable=invalid-name # Parse data for row in trs: tds = row.find_all("td") - if len(tds) > 10: + if len(tds) > 3: if tds[1].getText().strip() != ident[3:]: continue links = tds[1].find_all("a") @@ -49,10 +49,10 @@ def update_TH(static_data: StaticData) -> DynamicData: # pylint: disable=invali # Parse data for row in trs: tds = row.find_all("td") - if len(tds) > 10: + if len(tds) > 11: if tds[1].getText().strip() != static_data.ident[3:]: continue - if str(tds[6]).find("Hochwassermeldepegel") != -1: + if str(tds[7]).find("Hochwassermeldepegel") != -1: if "w3-purple" in row["class"]: stage = 4 elif "w3-red" in row["class"]: @@ -66,10 +66,10 @@ def update_TH(static_data: StaticData) -> DynamicData: # pylint: disable=invali else: stage = None last_update = convert_to_datetime( - tds[7].getText().strip(), "%d.%m.%Y %H:%M" + tds[8].getText().strip(), "%d.%m.%Y %H:%M" ) - level = convert_to_float(tds[8].getText().strip(), True) - flow = convert_to_float(tds[10].getText().strip(), True) + level = convert_to_float(tds[9].getText().strip(), True) + flow = convert_to_float(tds[11].getText().strip(), True) return DynamicData( level=level, stage=stage, flow=flow, last_update=last_update )