|
|
|
@ -57,8 +57,9 @@ WEATHER_CODE_MAP = {
|
|
|
|
|
"900": "热", "901": "冷", "999": "未知"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def fetch_city_info(location, api_key):
|
|
|
|
|
url = f"https://geoapi.qweather.com/v2/city/lookup?key={api_key}&location={location}&lang=zh"
|
|
|
|
|
|
|
|
|
|
def fetch_city_info(weather_url, location, api_key):
|
|
|
|
|
url = f"{weather_url}v2/city/lookup?key={api_key}&location={location}&lang=zh"
|
|
|
|
|
response = requests.get(url, headers=HEADERS).json()
|
|
|
|
|
return response.get('location', [])[0] if response.get('location') else None
|
|
|
|
|
|
|
|
|
@ -97,10 +98,11 @@ def parse_weather_info(soup):
|
|
|
|
|
def get_weather(conn, location: str = None, lang: str = "zh_CN"):
|
|
|
|
|
api_key = conn.config["plugins"]["get_weather"]["api_key"]
|
|
|
|
|
default_location = conn.config["plugins"]["get_weather"]["default_location"]
|
|
|
|
|
weather_url = conn.config["plugins"]["get_weather"]["weather_url"]
|
|
|
|
|
location = location or conn.client_ip_info.get("city") or default_location
|
|
|
|
|
logger.bind(tag=TAG).debug(f"获取天气: {location}")
|
|
|
|
|
|
|
|
|
|
city_info = fetch_city_info(location, api_key)
|
|
|
|
|
city_info = fetch_city_info(weather_url, location, api_key)
|
|
|
|
|
if not city_info:
|
|
|
|
|
return ActionResponse(Action.REQLLM, f"未找到相关的城市: {location},请确认地点是否正确", None)
|
|
|
|
|
|
|
|
|
@ -120,4 +122,4 @@ def get_weather(conn, location: str = None, lang: str = "zh_CN"):
|
|
|
|
|
"参数为0的值不需要报告给用户,每次都报告体感温度,根据语境选择合适的参数内容告知用户,并对参数给出相应评价)"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return ActionResponse(Action.REQLLM, weather_report, None)
|
|
|
|
|
return ActionResponse(Action.REQLLM, weather_report, None)
|
|
|
|
|