Skip to content

Commit c306881

Browse files
committed
CHG: Revert changes done in 1.0.4
1 parent b0f9481 commit c306881

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5 (2022-01-23)
2+
### Changed
3+
- Revert changes done in 1.0.4
4+
15
## 1.0.4 (2021-06-06)
26
### Changed
37
- Warncell ID handling due to changes in DWD api

dwdwfsapi/weatherwarnings.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,42 @@ def __generate_query(self, identifier):
230230
"dwd:Warngebiete_Kueste": "dwd:Warnungen_Kueste",
231231
}
232232

233-
identifier = str(identifier)
234233
region_query = {}
234+
# Numbers represent warncell ids
235+
if isinstance(identifier, int) or identifier.isnumeric():
236+
region_query["CQL_FILTER"] = f"WARNCELLID='{identifier}'"
237+
else:
238+
region_query["CQL_FILTER"] = f"NAME='{identifier}'"
235239

236-
found_cnt = 0
237240
for region in weather_warnings_query_mapping:
238241
region_query["typeName"] = region
239242
result = query_dwd(**region_query)
240243
if result is not None:
241-
for res in result["features"]:
242-
if (identifier in res["id"]) or (
243-
identifier == res["properties"]["NAME"]
244-
):
245-
cell_id = res["id"][res["id"].rfind(".") + 1 :]
246-
if cell_id.isnumeric():
247-
self.warncell_id = int(cell_id)
248-
self.warncell_name = res["properties"]["NAME"]
249-
self.__query = {
250-
"typeName": weather_warnings_query_mapping[
251-
region
252-
]
253-
}
254-
found_cnt += 1
255-
if found_cnt > 1:
256-
self.warncell_name += " (not unique used ID)!"
244+
if result["numberReturned"] > 0:
245+
self.warncell_id = result["features"][0]["properties"][
246+
"WARNCELLID"
247+
]
248+
self.warncell_name = result["features"][0]["properties"][
249+
"NAME"
250+
]
251+
# More than one match found. Can only happen if search is
252+
# done by name.
253+
if result["numberReturned"] > 1:
254+
self.warncell_name += " (not unique used ID)!"
255+
256+
self.__query = {
257+
"typeName": weather_warnings_query_mapping[region]
258+
}
259+
# Special handling for counties
260+
if region == "dwd:Warngebiete_Kreise":
261+
self.__query[
262+
"CQL_FILTER"
263+
] = f"GC_WARNCELLID='{self.warncell_id}'"
264+
else:
265+
self.__query[
266+
"CQL_FILTER"
267+
] = f"WARNCELLID='{self.warncell_id}'"
268+
break
257269

258270
def __parse_result(self, json_obj):
259271
"""Parse the retrieved data."""
@@ -277,19 +289,18 @@ def __parse_result(self, json_obj):
277289

278290
if json_obj["numberReturned"]:
279291
for feature in json_obj["features"]:
280-
if str(self.warncell_id) in feature["id"]:
281-
warning = convert_warning_data(feature["properties"])
282-
283-
if warning["urgency"] == "immediate":
284-
current_warnings.append(warning)
285-
current_maxlevel = max(
286-
warning["level"], current_maxlevel
287-
)
288-
else:
289-
expected_warnings.append(warning)
290-
expected_maxlevel = max(
291-
warning["level"], expected_maxlevel
292-
)
292+
warning = convert_warning_data(feature["properties"])
293+
294+
if warning["urgency"] == "immediate":
295+
current_warnings.append(warning)
296+
current_maxlevel = max(
297+
warning["level"], current_maxlevel
298+
)
299+
else:
300+
expected_warnings.append(warning)
301+
expected_maxlevel = max(
302+
warning["level"], expected_maxlevel
303+
)
293304

294305
self.current_warning_level = current_maxlevel
295306
self.current_warnings = current_warnings

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
EMAIL = "stephan192@outlook.com"
1616
AUTHOR = "stephan192"
1717
REQUIRES_PYTHON = ">=3.6"
18-
VERSION = "1.0.4"
18+
VERSION = "1.0.5"
1919

2020
# Define required packages
2121
REQUIRES = ["requests>=2.23.0,<3", "ciso8601>=2.1.3,<3", "urllib3>=1.25.8,<2"]

0 commit comments

Comments
 (0)