MihoyoBBSTools/main_multi.py
2022-10-27 16:13:29 +08:00

79 lines
2.6 KiB
Python
Raw Permalink 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.

import os
import sys
import main
import time
import push
import config
import random
import setting
from loghelper import log
from error import CookieError
# 搜索配置文件
def fund_config(ext: str) -> list:
file_name = []
for files in os.listdir(config.path):
if os.path.splitext(files)[1] == ext:
file_name.append(files)
return file_name
def main_multi(autorun: bool):
log.info("AutoMihoyoBBS Multi User mode")
log.info("正在搜索配置文件!")
config_list = fund_config('.yaml')
if len(config_list) == 0:
log.warning("未检测到配置文件请确认config文件夹存在.yaml后缀名的配置文件")
exit(1)
if autorun:
log.info(f"已搜索到{len(config_list)}个配置文件,正在开始执行!")
else:
log.info(f"已搜索到{len(config_list)}个配置文件,请确认是否无多余文件!\r\n{config_list}")
try:
input("请输入回车继续需要重新搜索配置文件请Ctrl+C退出脚本")
except KeyboardInterrupt:
exit(0)
results = {"ok": [], "close": [], "error": [], "captcha": []}
for i in iter(config_list):
log.info(f"正在执行{i}")
setting.mihoyobbs_List_Use = []
config.config_Path = f"{config.path}/{i}"
try:
run_code, run_message = main.main()
except CookieError:
results["error"].append(i)
else:
if run_code == 0:
results["ok"].append(i)
elif run_code == 3:
results["captcha"].append(i)
else:
results["close"].append(i)
log.info(f"{i}执行完毕")
time.sleep(random.randint(3, 10))
print("")
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"]} '
log.info(push_message)
status = 0
if len(results["error"]) == len(config_list):
status = 1
elif len(results["error"]) != 0:
status = 2
elif len(results["captcha"]) != 0:
status = 3
push.push(status, push_message)
if __name__ == "__main__":
if (len(sys.argv) >= 2 and sys.argv[1] == "autorun") or os.getenv("AutoMihoyoBBS_autorun") == "1":
autorun = True
else:
autorun = False
main_multi(autorun)
exit(0)
pass