From e4db7d5dea06d4b36085e24e180651e0c7b0d572 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Mon, 30 Mar 2026 19:14:00 +0800 Subject: [PATCH] Fix Istanbul MGM station and province matching --- src/data_collection/mgm_sources.py | 12 +++++++++--- src/data_collection/weather_sources.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/data_collection/mgm_sources.py b/src/data_collection/mgm_sources.py index a43473c7..c035bcf5 100644 --- a/src/data_collection/mgm_sources.py +++ b/src/data_collection/mgm_sources.py @@ -1,5 +1,6 @@ from __future__ import annotations +import unicodedata from datetime import datetime, timedelta from typing import Dict, Optional @@ -9,6 +10,11 @@ from src.utils.metrics import record_source_call class MgmSourceMixin: + @staticmethod + def _normalize_mgm_text(value: str) -> str: + text = unicodedata.normalize("NFD", str(value or "")) + return "".join(ch for ch in text if unicodedata.category(ch) != "Mn").lower() + def fetch_from_mgm(self, istno: str) -> Optional[Dict]: """ 从土耳其气象局 (MGM) 获取实时数据和预测 (由用户提供其内部 API) @@ -76,7 +82,7 @@ class MgmSourceMixin: "station_name": latest.get("istasyonAd") or latest.get("adi") or latest.get("merkezAd") - or "Ankara Bölge", + or f"MGM Station {istno}", } # 2. 每日预报 @@ -251,10 +257,10 @@ class MgmSourceMixin: metadata = getattr(self, "mgm_stations_meta", {}) # 2. 找出属于该省份的所有站点 istNo - province_upper = province.upper() + province_normalized = self._normalize_mgm_text(province) province_ist_nos = [ ist_no for ist_no, s in metadata.items() - if (s.get("il") or "").upper() == province_upper + if self._normalize_mgm_text(s.get("il") or "") == province_normalized ] if not province_ist_nos: diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index e0d73221..e28718fa 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -97,7 +97,7 @@ class WeatherDataCollector(OpenMeteoCacheMixin, SettlementSourceMixin, MetarSour TURKISH_PROVINCES = { "ankara": ("17128", "Ankara"), - "istanbul": ("17060", "Istanbul"), + "istanbul": ("17058", "Istanbul"), } def __init__(self, config: dict):