天气丰富一下
This commit is contained in:
@@ -560,36 +560,68 @@ class WeatherPlugin(MessagePluginInterface):
|
|||||||
|
|
||||||
# --- 旧版兼容方法,用于普通查询 ---
|
# --- 旧版兼容方法,用于普通查询 ---
|
||||||
async def _get_weather_text_response(self, city_name: str) -> str:
|
async def _get_weather_text_response(self, city_name: str) -> str:
|
||||||
"""普通查询流程:查找 -> 获取 -> 拼接"""
|
|
||||||
# 1. 查 ID
|
|
||||||
city_info = await self._lookup_city_info(city_name)
|
city_info = await self._lookup_city_info(city_name)
|
||||||
if not city_info: return ""
|
if not city_info: return ""
|
||||||
|
cid = city_info.get('id')
|
||||||
cid = city_info['id']
|
|
||||||
|
|
||||||
# 2. 查天气
|
|
||||||
raw = await self._fetch_weather_by_id(cid)
|
raw = await self._fetch_weather_by_id(cid)
|
||||||
if not raw: return ""
|
if not raw: return ""
|
||||||
|
now = raw.get('now', {})
|
||||||
# 3. 拼接
|
daily = raw.get('daily_forecast', [])
|
||||||
geo_str = f"{city_info['country']}{city_info['adm1']}{city_info['adm2']}"
|
today = daily[0] if daily else {}
|
||||||
now = raw['now']
|
history = self.redis_manager.get_history(cid) if self.redis_manager else None
|
||||||
daily = raw['daily_forecast']
|
update_hm = str(raw.get('updateTime', ''))[11:16]
|
||||||
|
geo_str = f"{city_info.get('country','')}{city_info.get('adm1','')}{city_info.get('adm2','')}"
|
||||||
msg = (
|
title = f"{geo_str} | {city_info.get('name','')}"
|
||||||
f"{geo_str} 实时天气☁️\n"
|
t_now = now.get('temp', '-')
|
||||||
f"⏰ {raw['updateTime'][11:16]}\n\n"
|
feels = now.get('feelsLike', '-')
|
||||||
f"🌡️ {now['temp']}℃ (体感{now['feelsLike']})\n"
|
text_now = now.get('text', '')
|
||||||
f"☁️ {now['text']}\n"
|
wind_dir = now.get('windDir', '')
|
||||||
f"🌬️ {now['windDir']} {now['windScale']}级\n"
|
wind_scale = now.get('windScale', '')
|
||||||
f"💦 湿度{now['humidity']}%\n"
|
humidity = now.get('humidity', '')
|
||||||
f"👀 能见度{now['vis']}km\n\n"
|
vis = now.get('vis', '')
|
||||||
f"☁️ 未来预报:\n"
|
t_min = str(today.get('tempMin', ''))
|
||||||
)
|
t_max = str(today.get('tempMax', ''))
|
||||||
for day in daily[0:3]:
|
text_day = today.get('textDay', '')
|
||||||
d = day['fxDate'][5:]
|
uv = str(today.get('uvIndex', ''))
|
||||||
msg += f"{d} {day['textDay']}|{day['tempMin']}~{day['tempMax']}℃\n"
|
precip = str(today.get('precip', ''))
|
||||||
return msg
|
pressure = str(today.get('pressure', ''))
|
||||||
|
sunrise = today.get('sunrise', '')
|
||||||
|
sunset = today.get('sunset', '')
|
||||||
|
alerts = self._check_alerts_and_history(today, history) if today else []
|
||||||
|
tips = self._generate_life_tips(today) if today else []
|
||||||
|
clothing = self._get_clothing_advice(int(t_min) if t_min.isdigit() else 0, int(t_max) if t_max.isdigit() else 0) if today else ""
|
||||||
|
lines = []
|
||||||
|
lines.append(f"📍 {title}")
|
||||||
|
lines.append(f"⏰ {update_hm}")
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"🌡️ {t_now}℃ (体感{feels}℃) | {text_now}")
|
||||||
|
lines.append(f"💧 湿度{humidity}% | 🌬️ {wind_dir} {wind_scale}级 | 👀 能见度{vis}km")
|
||||||
|
if today:
|
||||||
|
lines.append(f"🗓️ 今日 {text_day} | {t_min}~{t_max}℃")
|
||||||
|
lines.append(f"☀️ 日出{sunrise} | <20> 日落{sunset}")
|
||||||
|
lines.append(f"🔆 紫外线{uv} | 🌧️ 降水{precip}mm | ⏱️ 气压{pressure}hPa")
|
||||||
|
if alerts:
|
||||||
|
lines.append("")
|
||||||
|
lines.append("⚠️ 特别关注")
|
||||||
|
for a in alerts[:3]:
|
||||||
|
lines.append(f"- {a}")
|
||||||
|
if tips:
|
||||||
|
lines.append("")
|
||||||
|
lines.append("<EFBFBD> 温馨提示")
|
||||||
|
for t in tips[:3]:
|
||||||
|
lines.append(f"- {t}")
|
||||||
|
if clothing:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"<EFBFBD> 穿衣:{clothing}")
|
||||||
|
if daily:
|
||||||
|
lines.append("")
|
||||||
|
lines.append("📈 未来3天")
|
||||||
|
for day in daily[0:3]:
|
||||||
|
d = str(day.get('fxDate',''))[5:]
|
||||||
|
lines.append(f"- {d} {day.get('textDay','')} | {day.get('tempMin','')}~{day.get('tempMax','')}℃")
|
||||||
|
lines.append("")
|
||||||
|
lines.append("回复 '取消订阅' 可退订每日早报")
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
def _extract_city_name(self, content: str) -> str:
|
def _extract_city_name(self, content: str) -> str:
|
||||||
content = content.replace(" ", "")
|
content = content.replace(" ", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user