update 0.0.6.2

This commit is contained in:
HibiKi
2021-11-23 21:44:59 +08:00
parent c802dfda22
commit 3de487fb24
251 changed files with 14413 additions and 14002 deletions
Regular → Executable
+33 -24
View File
@@ -1,11 +1,10 @@
from utils.message_builder import image
from utils.user_agent import get_user_agent
from configs.path_config import TEXT_PATH
from configs.config import NICKNAME
from typing import List
from nonebot import Driver
from pathlib import Path
import aiohttp
from utils.http_utils import AsyncHttpx
import ujson as json
import nonebot
@@ -17,37 +16,44 @@ data = {}
async def get_weather_of_city(city: str) -> str:
"""
获取城市天气数据
:param city: 城市
"""
code = _check_exists_city(city)
if code == 999:
return "不要查一个省份的天气啊,很累人的!"
elif code == 998:
return f"{NICKNAME}没查到!!试试查火星的天气?"
else:
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
async with session.get(
f"http://wthrcdn.etouch.cn/weather_mini?city={city}", timeout=5
) as res:
data_json = json.loads(await res.text(encoding="utf8"))
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
else:
return "好像出错了?"
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
else:
return "好像出错了?再试试?"
# 城市是否存在或是否是省份
def _check_exists_city(city: str) -> int:
"""
检测城市是否存在合法
:param city: 城市名称
"""
global data
city = city if city[-1] != "市" else city[:-1]
for province in data.keys():
@@ -61,6 +67,9 @@ def _check_exists_city(city: str) -> int:
def get_city_list() -> List[str]:
"""
获取城市列表
"""
global data
if not data:
try: