mirror of
https://github.com/0-8-4/miui-auto-tasks.git
synced 2024-11-24 17:19:41 +00:00
56c27977da
* 修复无法获取成长值的问题 更改成长值获取接口 * 修复无法获取成长值的问题 更改成长值获取接口 * 改用正则获取成长值 * 推送配置说明 * 更新推送 * 更新推送 * Update config.yaml * Update config.yaml * Update requirements.txt * Update config.yaml * format the file * 提升版本号 * 提升版本号 * 提升版本号 * 修复取消点赞出错 * feat: 重构项目 * chore: add Exception * add: repo report link * feat: 添加token的获取 * chore: 修正签到参数 * Delete utils directory * Delete config.yaml * Delete miuitask.py * feat: 重构项目 * Create __init__.py * feat: 重构项目 * Create 1 * feat: 重构项目 * add: 添加cryptography依赖 * Delete utils/api/1 * chore: 使用yaml储存数据 * chore: 添加token异常提示 chore: 修正部分数据结构 * imp: add system info output * imp: auto reformat by PyCharm * imp: 增加鸣谢 * imp: 修改主程序名称 * fix: 添加被删除的文件 * imp: 根据新版本 修改GitHub Action 脚本 * add: 添加tenacity重试库,部分get_token添加重试机制 chore: 将token.py重命名为utils.py chore: 添加captcha.py,用于用户自行解决验证码 * 增加信息显示 增加显示项目信息及系统信息 * imp: 修复github action 脚本 * imp: auto reformat by PyCharm --------- Co-authored-by: 0-8-4 <ljd69154@liangjundi.cn> Co-authored-by: TardisX <ranoklx@gmail.com>
138 lines
3.2 KiB
Python
138 lines
3.2 KiB
Python
from typing import (Any, Dict, NamedTuple, Optional)
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class ApiResultHandler(BaseModel):
|
|
"""
|
|
API返回的数据处理器
|
|
"""
|
|
content: Dict[str, Any]
|
|
"""API返回的JSON对象序列化以后的Dict对象"""
|
|
data: Optional[Dict[str, Any]] = None
|
|
"""API返回的数据体"""
|
|
message: str = ""
|
|
"""API返回的消息内容"""
|
|
status: Optional[int] = None
|
|
"""API返回的状态码"""
|
|
|
|
def __init__(self, content: Dict[str, Any]):
|
|
super().__init__(content=content)
|
|
|
|
for key in ["data", "entity"]:
|
|
if self.data is None:
|
|
self.data = self.content.get(key)
|
|
else:
|
|
break
|
|
|
|
for key in ["code", "status"]:
|
|
if self.status is None:
|
|
self.status = self.content.get(key)
|
|
|
|
for key in ["desc", "message"]:
|
|
if self.message == "":
|
|
self.message = self.content.get(key, "")
|
|
|
|
@property
|
|
def success(self):
|
|
"""
|
|
是否成功
|
|
"""
|
|
return self.status in [0, 200] or self.message in ["成功", "OK", "success"]
|
|
|
|
|
|
class LoginResultHandler(ApiResultHandler):
|
|
"""
|
|
登录API返回的数据处理器
|
|
"""
|
|
pwd: Optional[int] = None
|
|
"""登录状态"""
|
|
location: Optional[str] = None
|
|
"""登录成功后的跳转地址"""
|
|
|
|
def __init__(self, content: Dict[str, Any]):
|
|
super().__init__(content=content)
|
|
|
|
self.pwd = self.content.get("pwd")
|
|
self.location = self.content.get("location")
|
|
|
|
@property
|
|
def need_captcha(self):
|
|
"""
|
|
是否需要验证码
|
|
"""
|
|
return self.status == 87001 or "验证码" in self.message
|
|
|
|
@property
|
|
def pwd_wrong(self):
|
|
"""
|
|
密码错误
|
|
"""
|
|
return self.status == 70016
|
|
|
|
|
|
class DailyTasksResult(NamedTuple):
|
|
"""
|
|
每日任务API返回的数据处理器
|
|
"""
|
|
name: str
|
|
"""任务名称"""
|
|
showType: bool
|
|
"""任务状态"""
|
|
desc: Optional[str]
|
|
"""任务描述"""
|
|
|
|
|
|
class SignResultHandler(ApiResultHandler):
|
|
"""
|
|
签到API返回的数据处理器
|
|
"""
|
|
|
|
growth: Optional[str] = None
|
|
"""签到成功后的成长值"""
|
|
|
|
def __init__(self, content: Dict[str, Any]):
|
|
super().__init__(content=content)
|
|
|
|
self.growth = self.content.get("entity", {}).get("score", "未知")
|
|
|
|
def __bool__(self):
|
|
"""
|
|
签到是否成功
|
|
"""
|
|
return self.success
|
|
|
|
@property
|
|
def ck_invalid(self):
|
|
"""
|
|
cookie是否失效
|
|
"""
|
|
return self.status == 401
|
|
|
|
|
|
class TokenResultHandler(ApiResultHandler):
|
|
"""
|
|
TOKEN数据处理器
|
|
"""
|
|
token: str = ""
|
|
|
|
def __init__(self, content: Dict[str, Any]):
|
|
super().__init__(content=content)
|
|
|
|
self.token = self.data.get("token", "")
|
|
|
|
@property
|
|
def need_verify(self):
|
|
"""需要验证码"""
|
|
return self.data.get("result") == False and self.data.get("url")
|
|
|
|
@property
|
|
def success(self):
|
|
"""是否成功获取TOKEN"""
|
|
return self.token != ""
|
|
|
|
class GeetestResult(NamedTuple):
|
|
"""人机验证结果数据"""
|
|
validate: str
|
|
challenge: str
|
|
|