main
HuangHai 3 months ago
parent 657c42f202
commit 7237d7134c

@ -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)

Loading…
Cancel
Save