fix: safely fallback to metric unit per city instead of overwriting F to C randomly; allow trend engine to run even if Open-Meteo drops

This commit is contained in:
2569718930@qq.com
2026-03-11 04:57:58 +08:00
parent 535b2b0446
commit c5010a8b97
2 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -386,8 +386,8 @@ def start_bot():
except Exception:
return None
temp_unit = open_meteo.get("unit", "celsius")
temp_symbol = "°F" if temp_unit == "fahrenheit" else "°C"
city_is_fahrenheit = city_name.strip().lower() in ["dallas", "new york", "chicago", "miami", "atlanta", "seattle"]
temp_symbol = "°F" if city_is_fahrenheit else "°C"
# --- 1. 紧凑 Header (城市 + 时间 + 风险状态) ---
local_time = open_meteo.get("current", {}).get("local_time", "")
+4 -3
View File
@@ -66,11 +66,12 @@ def analyze_weather_trend(
nws = weather_data.get("nws", {})
empty_result = ("", "", {})
if not metar or not open_meteo:
if not metar and not mgm:
return empty_result
max_so_far = _sf(metar.get("current", {}).get("max_temp_so_far"))
cur_temp = _sf(metar.get("current", {}).get("temp"))
max_so_far = _sf(metar.get("current", {}).get("max_temp_so_far")) if metar else _sf(mgm.get("current", {}).get("mgm_max_temp"))
cur_temp = _sf(metar.get("current", {}).get("temp")) if metar else _sf(mgm.get("current", {}).get("temp"))
daily = open_meteo.get("daily", {})
hourly = open_meteo.get("hourly", {})
times = hourly.get("time", [])