diff --git a/bot_listener.py b/bot_listener.py index 93818b90..906d0fd3 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -325,6 +325,13 @@ def start_bot(): msg_lines.append(f" 🌬️ {dir_str}{wind_dir}° / {mgm_curr.get('wind_speed_ms')} m/s") if mgm_curr.get("rain_24h") is not None: msg_lines.append(f" 🌧️ 24h 降水: {mgm_curr.get('rain_24h')}mm") + + if mgm_curr.get("time"): + # 处理 MGM 原始时间格式 (例如 2026-02-08 13:00) + obs_time = mgm_curr.get("time") + if " " in obs_time: + obs_time = obs_time.split(" ")[1] + msg_lines.append(f" 🕐 观测: {obs_time} (官方)") if metar: icao = metar.get("icao", "") diff --git a/check_freshness.py b/check_freshness.py new file mode 100644 index 00000000..acb9a730 --- /dev/null +++ b/check_freshness.py @@ -0,0 +1,23 @@ +import requests +import json +import time + +def test_mgm(istno): + # 添加时间戳防止缓存 + url = f"https://servis.mgm.gov.tr/web/sondurumlar?istno={istno}&_={int(time.time()*1000)}" + headers = { + "Origin": "https://www.mgm.gov.tr", + "User-Agent": "Mozilla/5.0" + } + try: + resp = requests.get(url, headers=headers) + if resp.status_code == 200: + data = resp.json() + print(json.dumps(data, indent=2, ensure_ascii=False)) + else: + print(f"Error: {resp.status_code}") + except Exception as e: + print(f"Exception: {e}") + +print("--- Station 17128 (Esenboğa) ---") +test_mgm(17128) diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index 6d7adeab..80a0e27f 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -332,24 +332,29 @@ class WeatherDataCollector: results = {} try: - # 1. 实时数据 - obs_resp = self.session.get(f"{base_url}/sondurumlar?istno={istno}", headers=headers, timeout=self.timeout) + # 1. 实时数据 (添加时间戳防止 CDN 缓存) + import time + obs_resp = self.session.get( + f"{base_url}/sondurumlar?istno={istno}&_={int(time.time()*1000)}", + headers=headers, + timeout=self.timeout + ) if obs_resp.status_code == 200: data = obs_resp.json() if data: latest = data[0] if isinstance(data, list) else data # MGM 数据字段映射 - # ruzgarHiz 通常为 m/s 或 km/h,根据用户反馈这里使用 m/s 逻辑 - ruz_hiz = latest.get("ruzgarHiz", 0) + # ruzgarHiz 实测为 km/h,转为 m/s 需要除以 3.6 + ruz_hiz_kmh = latest.get("ruzgarHiz", 0) results["current"] = { "temp": latest.get("sicaklik"), "feels_like": latest.get("hissedilenSicaklik") or latest.get("sicaklik"), "humidity": latest.get("nem"), - "wind_speed_ms": ruz_hiz, - "wind_speed_kt": round(ruz_hiz * 1.94, 1) if ruz_hiz is not None else None, # 如果是 m/s 转 kt + "wind_speed_ms": round(ruz_hiz_kmh / 3.6, 1) if ruz_hiz_kmh is not None else None, + "wind_speed_kt": round(ruz_hiz_kmh / 1.852, 1) if ruz_hiz_kmh is not None else None, "wind_dir": latest.get("ruzgarYon"), "rain_24h": latest.get("toplamYagis"), - "time": latest.get("veriZamani"), + "time": latest.get("veriZamani"), # 观测时间 "station_name": latest.get("istasyonAd") or latest.get("adi") or latest.get("merkezAd") or "Ankara Esenboğa" }