zhenxun_bot/zhenxun/plugins/alapi/_data_source.py
2024-03-10 00:50:20 +08:00

30 lines
919 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from zhenxun.configs.config import Config
from zhenxun.utils.http_utils import AsyncHttpx
async def get_data(url: str, params: dict | None = None) -> tuple[dict | str, int]:
"""获取ALAPI数据
参数:
url: 请求链接
params: 参数
返回:
tuple[dict | str, int]: 返回信息
"""
if not params:
params = {}
params["token"] = Config.get_config("alapi", "ALAPI_TOKEN")
try:
data = (await AsyncHttpx.get(url, params=params, timeout=5)).json()
if data["code"] == 200:
if not data["data"]:
return "没有搜索到...", 997
return data, 200
else:
if data["code"] == 101:
return "缺失ALAPI TOKEN请在配置文件中填写", 999
return f'发生了错误...code{data["code"]}', 999
except TimeoutError:
return "超时了....", 998