From f2dac9b6222e18cd4018e4b174382c4ef66762f5 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 8 Feb 2026 03:15:56 +0800 Subject: [PATCH] feat: Implement city risk profile data collection and integrate it with the bot listener. --- bot_listener.py | 16 +++++++++------- src/data_collection/city_risk_profiles.py | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bot_listener.py b/bot_listener.py index dd5f23dd..dc436132 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -177,7 +177,15 @@ def start_bot(): weather_data = weather.fetch_all_sources(city_name, lat=coords["lat"], lon=coords["lon"]) msg_lines = [f"📍 {city_name.title()} 天气详情"] - 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", []) diff --git a/src/data_collection/city_risk_profiles.py b/src/data_collection/city_risk_profiles.py index d3ab4846..751a9358 100644 --- a/src/data_collection/city_risk_profiles.py +++ b/src/data_collection/city_risk_profiles.py @@ -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"]: