@@ -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
0 commit comments