From d4314ff5d77a3f90cd66f667fa1cb55f19170f66 Mon Sep 17 00:00:00 2001 From: AmandaloveYang <2569718930@qq.com> Date: Mon, 16 Feb 2026 11:09:56 +0800 Subject: [PATCH] feat: show max temperature time in METAR display --- bot_listener.py | 9 ++++++++- src/data_collection/weather_sources.py | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bot_listener.py b/bot_listener.py index a8902f97..0bad538c 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -437,6 +437,7 @@ def start_bot(): # 基础数据优先用 METAR cur_temp = metar.get("current", {}).get("temp") if metar else mgm.get("current", {}).get("temp") max_p = metar.get("current", {}).get("max_temp_so_far") if metar else None + max_p_time = metar.get("current", {}).get("max_temp_time") if metar else None obs_t_str = "N/A" main_source = "METAR" if metar else "MGM" @@ -467,7 +468,13 @@ def start_bot(): m_time = m_time.split(" ")[1][:5] obs_t_str = m_time - msg_lines.append(f"\n✈️ 实测 ({main_source}): {cur_temp}{temp_symbol}" + (f" (最高: {max_p}{temp_symbol})" if max_p else "") + f" | {obs_t_str}") + max_str = "" + if max_p is not None: + max_str = f" (最高: {max_p}{temp_symbol}" + if max_p_time: + max_str += f" @{max_p_time}" + max_str += ")" + msg_lines.append(f"\n✈️ 实测 ({main_source}): {cur_temp}{temp_symbol}{max_str} | {obs_t_str}") if mgm: m_c = mgm.get("current", {}) diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index bc6278fe..c0fc4c91 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -260,6 +260,7 @@ class WeatherDataCollector: utc_midnight = local_midnight - timedelta(seconds=utc_offset) max_so_far_c = -999 + max_temp_time = None for obs in data: obs_report_time = obs.get("reportTime", "") try: @@ -271,6 +272,9 @@ class WeatherDataCollector: t = obs.get("temp") if t is not None and t > max_so_far_c: max_so_far_c = t + # 转为当地时间并记录 + local_report = report_dt + timedelta(seconds=utc_offset) + max_temp_time = local_report.strftime("%H:%M") except: continue @@ -295,6 +299,7 @@ class WeatherDataCollector: "current": { "temp": round(temp, 1) if temp is not None else None, "max_temp_so_far": round(max_so_far, 1) if max_so_far is not None else None, + "max_temp_time": max_temp_time, "dewpoint": round(dewp, 1) if dewp is not None else None, "humidity": latest.get("rh"), "wind_speed_kt": latest.get("wspd"),