lhpapi 1.0.8__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,7 @@
1
+ ## 1.0.9 (2025-12-18)
2
+ ### Fixed
3
+ - Fix SH pegel page scraping
4
+
1
5
  ## 1.0.8 (2025-12-09)
2
6
  ### Fixed
3
7
  - Fix TH pegel page scraping
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lhpapi
3
- Version: 1.0.8
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.8"
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:
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
File without changes