From d39dfbe62fb2982d622a3ea95a9a62851c52ac4f Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sun, 13 Nov 2022 02:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=A9=E6=B0=94api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ plugins/weather/data_source.py | 35 +++++++++++++++------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 0ee761f8..3c7a0725 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,10 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能 ## 更新 +### 2022/11/13 + +* 更新天气api + ### 2022/11/12 * 更新yiqing插件数据显示 [@pull/1168](https://github.com/HibiKier/zhenxun_bot/pull/1168) diff --git a/plugins/weather/data_source.py b/plugins/weather/data_source.py index 3e542aee..8fd54f5c 100755 --- a/plugins/weather/data_source.py +++ b/plugins/weather/data_source.py @@ -25,27 +25,22 @@ async def get_weather_of_city(city: str) -> str: elif code == 998: return f"{NICKNAME}没查到!!试试查火星的天气?" else: - data_json = json.loads( - ( - await AsyncHttpx.get( - f"http://wthrcdn.etouch.cn/weather_mini?city={city}" - ) - ).text - ) - if "desc" in data_json: - if data_json["desc"] == "invilad-citykey": - return f"{NICKNAME}没查到!!试试查火星的天气?" + image("shengqi", "zhenxun") - elif data_json["desc"] == "OK": - w_type = data_json["data"]["forecast"][0]["type"] - w_max = data_json["data"]["forecast"][0]["high"][3:] - w_min = data_json["data"]["forecast"][0]["low"][3:] - fengli = data_json["data"]["forecast"][0]["fengli"][9:-3] - ganmao = data_json["data"]["ganmao"] - fengxiang = data_json["data"]["forecast"][0]["fengxiang"] - repass = f"{city}的天气是 {w_type} 天\n最高温度: {w_max}\n最低温度: {w_min}\n风力: {fengli} {fengxiang}\n{ganmao}" - return repass + data_json = ( + await AsyncHttpx.get( + f"https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=43656176&appsecret=I42og6Lm&ext=&cityid=&city={city[:-1]}" + ) + ).json() + if wh := data_json.get('data'): + w_type = wh[0]["wea_day"] + w_max = wh[0]["tem1"] + w_min = wh[0]["tem2"] + fengli = wh[0]["win_speed"] + ganmao = wh[0]["narrative"] + fengxiang = ','.join(wh[0].get('win', [])) + repass = f"{city}的天气是 {w_type} 天\n最高温度: {w_max}\n最低温度: {w_min}\n风力: {fengli} {fengxiang}\n{ganmao}" + return repass else: - return "好像出错了?再试试?" + return data_json.get("errmsg") or "好像出错了?再试试?" def _check_exists_city(city: str) -> int: