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