lhpapi 1.0.3__tar.gz → 1.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lhpapi-1.0.3 → lhpapi-1.0.5}/CHANGELOG.md +10 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/LICENSE +1 -1
- {lhpapi-1.0.3 → lhpapi-1.0.5}/PKG-INFO +2 -2
- {lhpapi-1.0.3 → lhpapi-1.0.5}/pyproject.toml +1 -1
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/__init__.py +8 -1
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/bb_api.py +11 -3
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/hh_api.py +2 -2
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/ni_api.py +13 -8
- {lhpapi-1.0.3 → lhpapi-1.0.5}/.gitignore +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/README.md +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/api_utils.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/be_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/bw_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/by_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/hb_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/he_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/mv_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/nw_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/rp_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/sh_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/sl_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/sn_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/st_api.py +0 -0
- {lhpapi-1.0.3 → lhpapi-1.0.5}/src/lhpapi/th_api.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: lhpapi
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.5
|
|
4
4
|
Summary: API to retrieve data from the Länderübergreifendes Hochwasser Portal (LHP)
|
|
5
5
|
Project-URL: Homepage, https://github.com/stephan192/lhpapi
|
|
6
6
|
Project-URL: Issues, https://github.com/stephan192/lhpapi/issues
|
|
@@ -6,7 +6,7 @@ from datetime import datetime
|
|
|
6
6
|
from types import FunctionType
|
|
7
7
|
from typing import Final
|
|
8
8
|
|
|
9
|
-
from .api_utils import DynamicData, LHPError, StaticData
|
|
9
|
+
from .api_utils import DynamicData, LHPError, StaticData, fetch_json
|
|
10
10
|
from .bb_api import init_BB, update_BB
|
|
11
11
|
from .be_api import init_BE, update_BE
|
|
12
12
|
from .bw_api import init_BW, update_BW
|
|
@@ -70,6 +70,13 @@ def update_lhp_data(static_data: StaticData) -> DynamicData:
|
|
|
70
70
|
)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
def get_all_stations() -> dict[str, str]:
|
|
74
|
+
"""Return all available stations."""
|
|
75
|
+
return fetch_json(
|
|
76
|
+
"https://raw.githubusercontent.com/stephan192/lhpapi/refs/heads/master/docs/pegel.json"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
73
80
|
class HochwasserPortalAPI:
|
|
74
81
|
"""API to retrieve the data."""
|
|
75
82
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from html import unescape
|
|
6
|
+
|
|
5
7
|
from .api_utils import (
|
|
6
8
|
DynamicData,
|
|
7
9
|
LHPError,
|
|
@@ -61,14 +63,17 @@ def fix_bb_encoding(string_in: str) -> str:
|
|
|
61
63
|
replace = False
|
|
62
64
|
else:
|
|
63
65
|
string_out = string_out + chr(num)
|
|
64
|
-
return string_out
|
|
66
|
+
return unescape(string_out)
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
def init_BB(ident: str) -> StaticData: # pylint: disable=invalid-name
|
|
68
70
|
"""Init data for Brandenburg."""
|
|
69
71
|
try:
|
|
70
72
|
# Get data
|
|
71
|
-
page = fetch_text(
|
|
73
|
+
page = fetch_text(
|
|
74
|
+
"https://pegelportal.brandenburg.de/start.php",
|
|
75
|
+
forced_encoding="ISO-8859-15",
|
|
76
|
+
)
|
|
72
77
|
lines = page.split("\n")
|
|
73
78
|
# Parse data
|
|
74
79
|
start_found = False
|
|
@@ -103,7 +108,10 @@ def update_BB(static_data: StaticData) -> DynamicData: # pylint: disable=invali
|
|
|
103
108
|
"""Update data for Brandenburg."""
|
|
104
109
|
try:
|
|
105
110
|
# Get data
|
|
106
|
-
page = fetch_text(
|
|
111
|
+
page = fetch_text(
|
|
112
|
+
"https://pegelportal.brandenburg.de/start.php",
|
|
113
|
+
forced_encoding="ISO-8859-15",
|
|
114
|
+
)
|
|
107
115
|
lines = page.split("\n")
|
|
108
116
|
# Parse data
|
|
109
117
|
start_found = False
|
|
@@ -54,14 +54,14 @@ def update_HH(static_data: StaticData) -> DynamicData: # pylint: disable=invali
|
|
|
54
54
|
text = div.getText()
|
|
55
55
|
level = convert_to_float(
|
|
56
56
|
text[
|
|
57
|
-
text.find("Wasserstand") + 11 : text.find("[NHN\
|
|
57
|
+
text.find("Wasserstand") + 11 : text.find("[NHN\u00a0+/-\u00a0cm]")
|
|
58
58
|
]
|
|
59
59
|
.replace(".", "")
|
|
60
60
|
.strip()
|
|
61
61
|
)
|
|
62
62
|
last_update = convert_to_datetime(
|
|
63
63
|
text[
|
|
64
|
-
text.find("\
|
|
64
|
+
text.find("\u00a0\u00a0\u00a0 um") + 6 : text.find("Trend")
|
|
65
65
|
].strip(),
|
|
66
66
|
"%d.%m.%Y %H:%M",
|
|
67
67
|
)
|
|
@@ -72,6 +72,8 @@ def update_NI(static_data: StaticData) -> DynamicData: # pylint: disable=invali
|
|
|
72
72
|
)
|
|
73
73
|
except (IndexError, KeyError):
|
|
74
74
|
value = None
|
|
75
|
+
if value == -888.0:
|
|
76
|
+
value = None
|
|
75
77
|
try:
|
|
76
78
|
if data["getStammdatenResult"][0]["Parameter"][0]["Einheit"] == "cm":
|
|
77
79
|
level = value
|
|
@@ -85,15 +87,18 @@ def update_NI(static_data: StaticData) -> DynamicData: # pylint: disable=invali
|
|
|
85
87
|
except (IndexError, KeyError):
|
|
86
88
|
level = None
|
|
87
89
|
flow = None
|
|
88
|
-
|
|
89
|
-
last_update = convert_to_datetime(
|
|
90
|
-
data["getStammdatenResult"][0]["Parameter"][0]["Datenspuren"][0][
|
|
91
|
-
"AktuellerMesswert_Zeitpunkt"
|
|
92
|
-
],
|
|
93
|
-
"%d.%m.%Y %H:%M",
|
|
94
|
-
)
|
|
95
|
-
except (IndexError, KeyError):
|
|
90
|
+
if (level is None) and (flow is None):
|
|
96
91
|
last_update = None
|
|
92
|
+
else:
|
|
93
|
+
try:
|
|
94
|
+
last_update = convert_to_datetime(
|
|
95
|
+
data["getStammdatenResult"][0]["Parameter"][0]["Datenspuren"][0][
|
|
96
|
+
"AktuellerMesswert_Zeitpunkt"
|
|
97
|
+
],
|
|
98
|
+
"%d.%m.%Y %H:%M",
|
|
99
|
+
)
|
|
100
|
+
except (IndexError, KeyError):
|
|
101
|
+
last_update = None
|
|
97
102
|
return DynamicData(level=level, stage=stage, flow=flow, last_update=last_update)
|
|
98
103
|
except Exception as err:
|
|
99
104
|
raise LHPError(err, "ni_api.py: update_NI()") from err
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|