feat: Implement city risk profile data collection and integrate it with the bot listener.

This commit is contained in:
2569718930@qq.com
2026-02-08 03:15:56 +08:00
parent 97589531e8
commit f2dac9b622
2 changed files with 11 additions and 8 deletions
+9 -7
View File
@@ -177,7 +177,15 @@ def start_bot():
weather_data = weather.fetch_all_sources(city_name, lat=coords["lat"], lon=coords["lon"])
msg_lines = [f"📍 <b>{city_name.title()} 天气详情</b>"]
msg_lines.append(f"⏱️ 生成时间: {datetime.now().strftime('%H:%M:%S')}")
# 立即显示城市风险档案,防止被淹没
risk_profile = get_city_risk_profile(city_name)
if risk_profile:
risk_warning = format_risk_warning(risk_profile, "°F") # 默认尝试用F显示偏差
if risk_warning:
msg_lines.append(risk_warning)
msg_lines.append(f"\n⏱️ 生成时间: {datetime.now().strftime('%H:%M:%S')}")
msg_lines.append("" * 20)
open_meteo = weather_data.get("open-meteo", {})
@@ -190,12 +198,6 @@ def start_bot():
time_only = local_time.split(" ")[1] if " " in local_time else local_time
msg_lines.append(f"🕐 当地时间: {time_only}")
# 显示城市风险档案
risk_profile = get_city_risk_profile(city_name)
if risk_profile:
risk_warning = format_risk_warning(risk_profile, temp_symbol)
if risk_warning:
msg_lines.append(f"\n{risk_warning}")
daily = open_meteo.get("daily", {})
dates = daily.get("time", [])
+2 -1
View File
@@ -170,6 +170,7 @@ def get_city_risk_profile(city_name: str) -> dict:
"tor": "toronto",
"ank": "ankara",
"sel": "seoul",
"seo": "seoul",
"wel": "wellington",
"ba": "buenos aires",
"首尔": "seoul",
@@ -212,7 +213,7 @@ def format_risk_warning(profile: dict, temp_symbol: str) -> str:
# 典型偏差
if profile["typical_bias_f"] >= 1.0:
lines.append(f" 📊 典型偏差: ±{profile['typical_bias_f']}{temp_symbol}")
lines.append(f" 📊 偏差: ±{profile['typical_bias_f']}{temp_symbol}")
# 偏差方向说明
if profile["bias_direction"]: