From d0c8ac3451a896e94906be3b31d528d1af95aa5a Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 8 Feb 2026 02:44:18 +0800 Subject: [PATCH] feat: introduce `WeatherDataCollector` module for multi-source weather data fetching from OpenWeatherMap, Visual Crossing, and NOAA METAR. --- bot_listener.py | 2 +- src/data_collection/weather_sources.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bot_listener.py b/bot_listener.py index 449368b5..8f317de3 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -201,7 +201,7 @@ def start_bot(): msg_lines.append(f"{indicator}{day_label}: 最高 {t}{temp_symbol} ⚠️") msg_lines.append(f" (NWS官方预报: {nws_high}{temp_symbol},差异 {diff:.1f}°)") else: - msg_lines.append(f"{indicator}{day_label}: 最高 {t}{temp_symbol} (NWS: {nws_high})") + msg_lines.append(f"{indicator}{day_label}: 最高 {t}{temp_symbol} (NWS: {nws_high}{temp_symbol})") else: msg_lines.append(f"{indicator}{day_label}: 最高 {t}{temp_symbol}") diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index ca66c7aa..b7b26842 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -416,16 +416,20 @@ class WeatherDataCollector: ecmwf_max = daily_data.get("temperature_2m_max_ecmwf_ifs04", []) hrrr_max = daily_data.get("temperature_2m_max_ncep_hrrr_conus", []) - # 记录多模型分歧 + # 记录今日模型分歧 daily_data["model_split"] = { "ecmwf": ecmwf_max[0] if ecmwf_max else None, "hrrr": hrrr_max[0] if hrrr_max else None } - # 核心修正:映射回标准键名 - if hrrr_max: - daily_data["temperature_2m_max"] = hrrr_max - elif ecmwf_max: - daily_data["temperature_2m_max"] = ecmwf_max + + # 智能合并:HRRR 仅覆盖 48 小时,远期用 ECMWF 补全 + merged_max = [] + for i in range(len(ecmwf_max)): + if i < len(hrrr_max) and hrrr_max[i] is not None: + merged_max.append(hrrr_max[i]) # 短期用 HRRR + else: + merged_max.append(ecmwf_max[i]) # 远期用 ECMWF + daily_data["temperature_2m_max"] = merged_max # 映射逐小时数据 hourly_data = data.get("hourly", {})