lhpapi 1.0.7__tar.gz → 1.0.9__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.
@@ -1,3 +1,11 @@
1
+ ## 1.0.9 (2025-12-18)
2
+ ### Fixed
3
+ - Fix SH pegel page scraping
4
+
5
+ ## 1.0.8 (2025-12-09)
6
+ ### Fixed
7
+ - Fix TH pegel page scraping
8
+
1
9
  ## 1.0.7 (2025-11-23)
2
10
  ### Fixed
3
11
  - Fix HE without flow
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lhpapi
3
- Version: 1.0.7
3
+ Version: 1.0.9
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "lhpapi"
7
- version = "1.0.7"
7
+ version = "1.0.9"
8
8
  authors = [
9
9
  { name="stephan192", email="stephan192@outlook.com" },
10
10
  ]
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from datetime import datetime
6
+
5
7
  from .api_utils import (
6
8
  DynamicData,
7
9
  LHPError,
@@ -13,6 +15,21 @@ from .api_utils import (
13
15
  )
14
16
 
15
17
 
18
+ def parse_timestamp(parts: list[str]) -> datetime:
19
+ """Parse timestamp with optional timezone."""
20
+ if len(parts) >= 5:
21
+ timezone = parts[4].strip("()")
22
+ else:
23
+ timezone = None
24
+ base_time = parts[2] + parts[3]
25
+
26
+ if timezone == "MEZ":
27
+ return convert_to_datetime(f"{base_time}+0100", "%d.%m.%Y%H:%M%z")
28
+ if timezone == "MESZ":
29
+ return convert_to_datetime(f"{base_time}+0200", "%d.%m.%Y%H:%M%z")
30
+ return convert_to_datetime(base_time, "%d.%m.%Y%H:%M")
31
+
32
+
16
33
  def init_SH(ident: str) -> StaticData: # pylint: disable=invalid-name
17
34
  """Init data for Schleswig-Holstein."""
18
35
  try:
@@ -67,28 +84,15 @@ def update_SH(static_data: StaticData) -> DynamicData: # pylint: disable=invali
67
84
  and element.attrs["class"][0] == "tooltip-content__w"
68
85
  ):
69
86
  element_text = element.getText().split()
70
- if element_text[1] == "cm":
87
+ if len(element_text) >= 4 and element_text[1] == "cm":
71
88
  level = convert_to_float(element_text[0], True)
72
- if element_text[4] == "(MEZ)":
73
- last_update = convert_to_datetime(
74
- element_text[2] + element_text[3] + "+0100",
75
- "%d.%m.%Y%H:%M%z",
76
- )
77
- elif element_text[4] == "(MESZ)":
78
- last_update = convert_to_datetime(
79
- element_text[2] + element_text[3] + "+0200",
80
- "%d.%m.%Y%H:%M%z",
81
- )
82
- else:
83
- last_update = convert_to_datetime(
84
- element_text[2] + element_text[3], "%d.%m.%Y%H:%M"
85
- )
89
+ last_update = parse_timestamp(element_text)
86
90
  if (
87
91
  element.name == "dd"
88
92
  and element.attrs["class"][0] == "tooltip-content__q"
89
93
  ):
90
94
  element_text = element.getText().split()
91
- if element_text[1] == "m3/s":
95
+ if len(element_text) >= 2 and element_text[1] == "m3/s":
92
96
  flow = convert_to_float(element_text[0], True)
93
97
  return DynamicData(level=level, stage=stage, flow=flow, last_update=last_update)
94
98
  except Exception as err:
@@ -23,7 +23,7 @@ def init_TH(ident: str) -> StaticData: # pylint: disable=invalid-name
23
23
  # Parse data
24
24
  for row in trs:
25
25
  tds = row.find_all("td")
26
- if len(tds) > 10:
26
+ if len(tds) > 3:
27
27
  if tds[1].getText().strip() != ident[3:]:
28
28
  continue
29
29
  links = tds[1].find_all("a")
@@ -49,10 +49,10 @@ def update_TH(static_data: StaticData) -> DynamicData: # pylint: disable=invali
49
49
  # Parse data
50
50
  for row in trs:
51
51
  tds = row.find_all("td")
52
- if len(tds) > 10:
52
+ if len(tds) > 11:
53
53
  if tds[1].getText().strip() != static_data.ident[3:]:
54
54
  continue
55
- if str(tds[6]).find("Hochwassermeldepegel") != -1:
55
+ if str(tds[7]).find("Hochwassermeldepegel") != -1:
56
56
  if "w3-purple" in row["class"]:
57
57
  stage = 4
58
58
  elif "w3-red" in row["class"]:
@@ -66,10 +66,10 @@ def update_TH(static_data: StaticData) -> DynamicData: # pylint: disable=invali
66
66
  else:
67
67
  stage = None
68
68
  last_update = convert_to_datetime(
69
- tds[7].getText().strip(), "%d.%m.%Y %H:%M"
69
+ tds[8].getText().strip(), "%d.%m.%Y %H:%M"
70
70
  )
71
- level = convert_to_float(tds[8].getText().strip(), True)
72
- flow = convert_to_float(tds[10].getText().strip(), True)
71
+ level = convert_to_float(tds[9].getText().strip(), True)
72
+ flow = convert_to_float(tds[11].getText().strip(), True)
73
73
  return DynamicData(
74
74
  level=level, stage=stage, flow=flow, last_update=last_update
75
75
  )
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
File without changes
File without changes
File without changes