2023-11-18 10:37:51 +00:00
|
|
|
# new Env("MIUI-Auto-Task") # pylint: disable=missing-module-docstring
|
2023-11-14 03:04:05 +00:00
|
|
|
# cron 30 8 * * * miuitask.py
|
|
|
|
|
2023-11-13 13:18:59 +00:00
|
|
|
import asyncio
|
|
|
|
|
2023-11-19 12:19:54 +00:00
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
|
2023-11-13 13:18:59 +00:00
|
|
|
from utils.api.login import Login
|
|
|
|
from utils.api.sign import BaseSign
|
|
|
|
from utils.config import ConfigManager
|
2023-11-19 12:19:54 +00:00
|
|
|
from utils.logger import get_message, log
|
2023-11-13 13:18:59 +00:00
|
|
|
from utils.request import notify_me
|
|
|
|
from utils.system_info import print_info
|
2023-11-19 12:19:54 +00:00
|
|
|
from utils.utils import get_token
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
_conf = ConfigManager.data_obj
|
|
|
|
|
2023-11-22 04:02:10 +00:00
|
|
|
|
2023-11-13 13:18:59 +00:00
|
|
|
async def main():
|
2023-11-18 10:37:51 +00:00
|
|
|
"""启动签到"""
|
2023-11-13 13:18:59 +00:00
|
|
|
print_info()
|
|
|
|
for account in _conf.accounts:
|
|
|
|
login_obj = Login(account)
|
2023-11-22 04:02:10 +00:00
|
|
|
if cookies := await login_obj.login():
|
2023-11-15 13:07:29 +00:00
|
|
|
token = await get_token(cookies["cUserId"])
|
2023-11-13 13:18:59 +00:00
|
|
|
sign_obj = BaseSign(cookies)
|
|
|
|
daily_tasks = await sign_obj.check_daily_tasks()
|
|
|
|
sign_task_obj = sign_obj.AVAILABLE_SIGNS # 签到任务对象合集
|
|
|
|
for task in daily_tasks:
|
|
|
|
if not task.showType:
|
|
|
|
log.info(f"开始执行{task.name}任务")
|
|
|
|
if task_obj := sign_task_obj.get(task.name): # 签到任务对象
|
2023-11-14 02:15:39 +00:00
|
|
|
if getattr(account, task_obj.__name__):
|
|
|
|
await task_obj(cookies, token).sign()
|
|
|
|
else:
|
|
|
|
log.info(f"任务{task.name}被禁用")
|
2023-11-13 13:18:59 +00:00
|
|
|
else:
|
|
|
|
log.error(f"未找到{task.name}任务")
|
|
|
|
else:
|
|
|
|
log.info(f"{task.name}任务已完成")
|
|
|
|
notify_me(get_message())
|
2021-08-16 03:39:26 +00:00
|
|
|
|
2021-09-17 00:08:26 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-11-24 07:56:12 +00:00
|
|
|
HOUR = _conf.preference.hour
|
|
|
|
MINUTE = _conf.preference.minute
|
|
|
|
if HOUR and MINUTE:
|
|
|
|
log.info(f"脚本将在每日{HOUR}:{MINUTE}自动运行")
|
2023-11-19 12:19:54 +00:00
|
|
|
# 创建一个新的事件循环
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
scheduler = AsyncIOScheduler()
|
2023-11-24 07:56:12 +00:00
|
|
|
scheduler.add_job(main, 'cron', hour=HOUR, minute=MINUTE, id='miuitask')
|
2023-11-19 12:19:54 +00:00
|
|
|
scheduler.start()
|
|
|
|
try:
|
|
|
|
loop.run_forever()
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
scheduler.shutdown()
|
|
|
|
else:
|
|
|
|
asyncio.run(main())
|