MihoyoBBSTools/main_multi.py

79 lines
2.6 KiB
Python
Raw Permalink Normal View History

2021-05-25 13:30:53 +00:00
import os
2021-05-27 13:25:58 +00:00
import sys
2021-05-25 13:30:53 +00:00
import main
import time
2022-01-09 09:31:44 +00:00
import push
2021-05-25 13:30:53 +00:00
import config
2021-06-06 09:50:00 +00:00
import random
2021-05-26 10:11:27 +00:00
import setting
2022-01-06 05:49:25 +00:00
from loghelper import log
from error import CookieError
2021-05-25 13:30:53 +00:00
2021-10-25 14:53:34 +00:00
# 搜索配置文件
2022-08-23 15:42:46 +00:00
def fund_config(ext: str) -> list:
2022-01-06 05:49:25 +00:00
file_name = []
2021-05-25 13:30:53 +00:00
for files in os.listdir(config.path):
2022-08-23 15:42:46 +00:00
if os.path.splitext(files)[1] == ext:
2022-01-06 05:49:25 +00:00
file_name.append(files)
return file_name
2021-05-25 13:30:53 +00:00
2021-10-25 14:53:34 +00:00
def main_multi(autorun: bool):
2022-01-06 05:49:25 +00:00
log.info("AutoMihoyoBBS Multi User mode")
log.info("正在搜索配置文件!")
2022-08-23 15:42:46 +00:00
config_list = fund_config('.yaml')
2022-01-06 05:49:25 +00:00
if len(config_list) == 0:
2022-08-23 15:42:46 +00:00
log.warning("未检测到配置文件请确认config文件夹存在.yaml后缀名的配置文件")
2021-08-03 02:58:32 +00:00
exit(1)
if autorun:
2022-01-06 05:49:25 +00:00
log.info(f"已搜索到{len(config_list)}个配置文件,正在开始执行!")
2021-05-29 01:34:21 +00:00
else:
2022-01-06 05:49:25 +00:00
log.info(f"已搜索到{len(config_list)}个配置文件,请确认是否无多余文件!\r\n{config_list}")
2021-05-30 04:27:16 +00:00
try:
input("请输入回车继续需要重新搜索配置文件请Ctrl+C退出脚本")
2022-04-24 05:06:26 +00:00
except KeyboardInterrupt:
2021-08-03 02:58:32 +00:00
exit(0)
results = {"ok": [], "close": [], "error": [], "captcha": []}
2022-01-06 05:49:25 +00:00
for i in iter(config_list):
log.info(f"正在执行{i}")
2021-05-26 10:11:27 +00:00
setting.mihoyobbs_List_Use = []
2021-10-25 14:53:34 +00:00
config.config_Path = f"{config.path}/{i}"
2022-01-06 03:27:24 +00:00
try:
2022-02-03 09:19:03 +00:00
run_code, run_message = main.main()
2022-01-06 05:49:25 +00:00
except CookieError:
2022-01-06 03:27:24 +00:00
results["error"].append(i)
else:
2022-01-09 07:25:47 +00:00
if run_code == 0:
results["ok"].append(i)
elif run_code == 3:
results["captcha"].append(i)
2022-01-09 07:25:47 +00:00
else:
results["close"].append(i)
2022-01-06 05:49:25 +00:00
log.info(f"{i}执行完毕")
2021-07-17 03:07:38 +00:00
time.sleep(random.randint(3, 10))
2022-01-06 05:58:38 +00:00
print("")
2022-04-24 05:06:26 +00:00
push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,' \
f'没执行{len(results["close"])}个,失败{len(results["error"])}' \
f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}\r\n' \
f'触发原神验证码的配置文件: {results["captcha"]} '
2022-01-09 09:31:44 +00:00
log.info(push_message)
2022-04-25 08:07:37 +00:00
status = 0
if len(results["error"]) == len(config_list):
status = 1
2022-04-25 22:54:34 +00:00
elif len(results["error"]) != 0:
2022-04-25 08:07:37 +00:00
status = 2
elif len(results["captcha"]) != 0:
status = 3
2022-04-25 08:07:37 +00:00
push.push(status, push_message)
2021-05-25 13:30:53 +00:00
2021-10-25 14:53:34 +00:00
2021-05-25 13:30:53 +00:00
if __name__ == "__main__":
2021-12-04 13:55:50 +00:00
if (len(sys.argv) >= 2 and sys.argv[1] == "autorun") or os.getenv("AutoMihoyoBBS_autorun") == "1":
autorun = True
else:
autorun = False
main_multi(autorun)
2021-08-03 02:58:32 +00:00
exit(0)
2021-10-25 14:53:34 +00:00
pass