From 8a5e8957c5c1acd95911c08b3a7745d88af29191 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Mon, 18 May 2026 18:23:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=20KNMI=20station=20ID=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8F=98=E6=9B=B4=EF=BC=9A3=E4=BD=8D?= =?UTF-8?q?=E7=A0=81=E2=86=925=E4=BD=8DWMO=E7=A0=81=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=89=8D=E5=AF=BC=E9=9B=B6=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data_collection/knmi_sources.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/data_collection/knmi_sources.py b/src/data_collection/knmi_sources.py index 720f4548..a88505cb 100644 --- a/src/data_collection/knmi_sources.py +++ b/src/data_collection/knmi_sources.py @@ -20,7 +20,7 @@ KNMI_VERSION = "1.0" KNMI_API_BASE = "https://api.dataplatform.knmi.nl/open-data/v1" KNMI_STATION = { "amsterdam": { - "station": "240", + "station": "06240", "icao": "EHAM", "label": "Schiphol 10min (KNMI)", }, @@ -117,20 +117,22 @@ class KnmiSourceMixin: try: stn = meta["station"] # Find station index - station_ids = list(nc.variables.get("station_id", [])[:]) - if not station_ids: - station_codes = [] - for s in nc.variables.get("station", []): - try: - station_codes.append(str(int(s))) - except Exception: - station_codes.append("") - station_ids = station_codes + station_var = nc.variables.get("station_id") or nc.variables.get("station") + station_ids = [] + for s in (station_var[:] if station_var is not None else []): + try: + val = str(int(s)) + except Exception: + val = str(s).strip() + station_ids.append(val) try: idx = station_ids.index(stn) except ValueError: - idx = station_ids.index(int(stn)) if stn.isdigit() else -1 + try: + idx = station_ids.index(str(int(stn))) + except (ValueError, TypeError): + idx = -1 if idx < 0 or idx >= len(station_ids): logger.warning("KNMI station {} not found in file", stn)