feat: add WeatherDataCollector class for fetching weather data from OpenWeatherMap, Visual Crossing, and NOAA METAR, including city-to-ICAO mapping.

This commit is contained in:
2569718930@qq.com
2026-02-08 02:30:19 +08:00
parent c065992fb0
commit f371721919
+9 -3
View File
@@ -364,7 +364,6 @@ class WeatherDataCollector:
# 处理多模型数据 (如果请求了 models 参数,返回结构会变化)
daily_data = data.get("daily", {})
if "temperature_2m_max_ecmwf_ifs" in daily_data:
# 获取首日的各模型峰值比较
ecmwf_max = daily_data.get("temperature_2m_max_ecmwf_ifs", [])
hrrr_max = daily_data.get("temperature_2m_max_hrrr_conus", [])
@@ -373,9 +372,16 @@ class WeatherDataCollector:
"ecmwf": ecmwf_max[0] if ecmwf_max else None,
"hrrr": hrrr_max[0] if hrrr_max else None
}
# 设置主显示值为 HRRR (当地高精)
# 核心修正:映射回标准键名
if hrrr_max:
daily_data["temperature_2m_max"] = hrrr_max
elif ecmwf_max:
daily_data["temperature_2m_max"] = ecmwf_max
# 映射逐小时数据
hourly_data = data.get("hourly", {})
if "temperature_2m_hrrr_conus" in hourly_data:
hourly_data["temperature_2m"] = hourly_data["temperature_2m_hrrr_conus"]
# 计算精确的当地时间
now_utc = datetime.utcnow()
@@ -391,7 +397,7 @@ class WeatherDataCollector:
"temp": current.get("temperature"),
"local_time": local_time_str,
},
"hourly": data.get("hourly", {}),
"hourly": hourly_data,
"daily": daily_data,
"unit": "fahrenheit" if use_fahrenheit else "celsius",
}