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:
@@ -364,7 +364,6 @@ class WeatherDataCollector:
|
|||||||
# 处理多模型数据 (如果请求了 models 参数,返回结构会变化)
|
# 处理多模型数据 (如果请求了 models 参数,返回结构会变化)
|
||||||
daily_data = data.get("daily", {})
|
daily_data = data.get("daily", {})
|
||||||
if "temperature_2m_max_ecmwf_ifs" in daily_data:
|
if "temperature_2m_max_ecmwf_ifs" in daily_data:
|
||||||
# 获取首日的各模型峰值比较
|
|
||||||
ecmwf_max = daily_data.get("temperature_2m_max_ecmwf_ifs", [])
|
ecmwf_max = daily_data.get("temperature_2m_max_ecmwf_ifs", [])
|
||||||
hrrr_max = daily_data.get("temperature_2m_max_hrrr_conus", [])
|
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,
|
"ecmwf": ecmwf_max[0] if ecmwf_max else None,
|
||||||
"hrrr": hrrr_max[0] if hrrr_max else None
|
"hrrr": hrrr_max[0] if hrrr_max else None
|
||||||
}
|
}
|
||||||
# 设置主显示值为 HRRR (当地高精)
|
# 核心修正:映射回标准键名
|
||||||
if hrrr_max:
|
if hrrr_max:
|
||||||
daily_data["temperature_2m_max"] = 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()
|
now_utc = datetime.utcnow()
|
||||||
@@ -391,7 +397,7 @@ class WeatherDataCollector:
|
|||||||
"temp": current.get("temperature"),
|
"temp": current.get("temperature"),
|
||||||
"local_time": local_time_str,
|
"local_time": local_time_str,
|
||||||
},
|
},
|
||||||
"hourly": data.get("hourly", {}),
|
"hourly": hourly_data,
|
||||||
"daily": daily_data,
|
"daily": daily_data,
|
||||||
"unit": "fahrenheit" if use_fahrenheit else "celsius",
|
"unit": "fahrenheit" if use_fahrenheit else "celsius",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user