Skip to content

Commit b0f9481

Browse files
committed
CHG: Warncell ID handling due to changes in DWD api
1 parent 60b37eb commit b0f9481

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
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.4 (2021-06-06)
2+
### Changed
3+
- Warncell ID handling due to changes in DWD api
4+
15
## 1.0.3 (2020-09-26)
26
### Added
37
- Urgency attribute added to warning dictionary

dwdwfsapi/weatherwarnings.py

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

233+
identifier = str(identifier)
233234
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}'"
239235

236+
found_cnt = 0
240237
for region in weather_warnings_query_mapping:
241238
region_query["typeName"] = region
242239
result = query_dwd(**region_query)
243240
if result is not None:
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
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)!"
269257

270258
def __parse_result(self, json_obj):
271259
"""Parse the retrieved data."""
@@ -289,18 +277,19 @@ def __parse_result(self, json_obj):
289277

290278
if json_obj["numberReturned"]:
291279
for feature in json_obj["features"]:
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-
)
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+
)
304293

305294
self.current_warning_level = current_maxlevel
306295
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.3"
18+
VERSION = "1.0.4"
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)