feat: Add a new WeatherDataCollector module for multi-source weather data retrieval and update bot_listener.py.
This commit is contained in:
@@ -191,6 +191,10 @@ def start_bot():
|
|||||||
nws_high = nws.get("today_high")
|
nws_high = nws.get("today_high")
|
||||||
|
|
||||||
for i, (d, t) in enumerate(zip(dates[:7], max_temps[:7])):
|
for i, (d, t) in enumerate(zip(dates[:7], max_temps[:7])):
|
||||||
|
# 跳过无效数据
|
||||||
|
if t is None:
|
||||||
|
continue
|
||||||
|
|
||||||
day_label = "今天" if d == city_today_str else d[5:]
|
day_label = "今天" if d == city_today_str else d[5:]
|
||||||
indicator = "👉 " if d == city_today_str else " "
|
indicator = "👉 " if d == city_today_str else " "
|
||||||
|
|
||||||
|
|||||||
@@ -425,10 +425,17 @@ class WeatherDataCollector:
|
|||||||
# 智能合并:HRRR 仅覆盖 48 小时,远期用 ECMWF 补全
|
# 智能合并:HRRR 仅覆盖 48 小时,远期用 ECMWF 补全
|
||||||
merged_max = []
|
merged_max = []
|
||||||
for i in range(len(ecmwf_max)):
|
for i in range(len(ecmwf_max)):
|
||||||
if i < len(hrrr_max) and hrrr_max[i] is not None:
|
hrrr_val = hrrr_max[i] if i < len(hrrr_max) else None
|
||||||
merged_max.append(hrrr_max[i]) # 短期用 HRRR
|
ecmwf_val = ecmwf_max[i] if i < len(ecmwf_max) else None
|
||||||
|
|
||||||
|
# 优先 HRRR,其次 ECMWF,都没有就跳过
|
||||||
|
if hrrr_val is not None:
|
||||||
|
merged_max.append(hrrr_val)
|
||||||
|
elif ecmwf_val is not None:
|
||||||
|
merged_max.append(ecmwf_val)
|
||||||
else:
|
else:
|
||||||
merged_max.append(ecmwf_max[i]) # 远期用 ECMWF
|
# 两个都没有,用占位符 (理论上不应该发生)
|
||||||
|
merged_max.append(ecmwf_val) # None
|
||||||
daily_data["temperature_2m_max"] = merged_max
|
daily_data["temperature_2m_max"] = merged_max
|
||||||
|
|
||||||
# 映射逐小时数据
|
# 映射逐小时数据
|
||||||
|
|||||||
Reference in New Issue
Block a user