-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.py
119 lines (103 loc) · 3.98 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import argparse
import ctypes
import datetime
import json
import sys
from pathlib import Path
from loguru import logger
from zafkiel import simple_report, auto_setup
from config import Config
from tasks.armada import Armada
from tasks.dorm_bonus import DormBonus
from tasks.errand import Errand
from tasks.expedition import Expeditions
from tasks.login import Login
from tasks.mail import Mail
from tasks.mission import Missions
from tasks.sweep import Sweep
from tasks.weekly_reward import WeeklyReward
logger.remove()
logger.add(sys.stdout, level="INFO", format="<green>{time:HH:mm:ss}</green> | "
"<level>{level: <7}</level> | "
"<level>{message}</level>",
)
date = datetime.datetime.now().strftime("%Y-%m-%d")
logger.add(f'./log/{date}/{date}.log', level="DEBUG", format="<green>{time:HH:mm:ss}</green> | "
"<level>{level: <7}</level> | "
"<level>{message}</level>",
)
def all_tasks(config):
try:
# 日常
Login(config).app_start()
Missions(config).run()
DormBonus(config).claim_stamina()
DormBonus(config).claim_gold()
Errand(config).run()
Expeditions(config).run()
Armada(config).run()
Sweep(config).run()
Missions(config).run()
Mail(config).run()
WeeklyReward(config).run()
# 结束游戏进程
Login(config).app_stop()
except Exception as e:
logger.exception(e)
raise
finally:
simple_report(__file__, log_path=Path(f'./log/{date}/report').resolve(), output=f'./log/{date}/report.html')
def single_task(config, task):
try:
if task != 'login':
auto_setup(str(Path.cwd()), logdir=f'./log/{date}/report', devices=["WindowsPlatform:///?title=崩坏3", ])
if task == 'armada':
Armada(config).run()
elif task == 'dorm_bonus':
DormBonus(config).run()
elif task == 'errand':
Errand(config).run()
elif task == 'expedition':
Expeditions(config).run()
elif task == 'login':
Login(config).app_start()
elif task == 'logout':
Login(config).app_stop()
simple_report(__file__, log_path=Path(f'./log/{date}/report').resolve(), output=f'./log/{date}/report.html')
elif task == 'mail':
Mail(config).run()
elif task == 'mission':
Missions(config).run()
elif task == 'sweep':
Sweep(config).run()
elif task == 'weekly_reward':
WeeklyReward(config).run()
except Exception as e:
simple_report(__file__, log_path=Path(f'./log/{date}/report').resolve(), output=f'./log/{date}/report.html')
logger.error(e)
raise
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--task', '-t',
choices=["armada", "dorm_bonus", "errand", "expedition", "login", "logout", "mail",
"mission", "sweep", "weekly_reward"],
help='Task name, one of "armada, dorm_bonus, errand, expedition, login, logout, mail, '
'mission, sweep, weekly_reward"')
parser.add_argument('--config_path', '-c', default='./config/config.json')
args = parser.parse_args()
if args.task:
config_path = Path(args.config_path).resolve()
if not config_path.exists():
logger.error(f'{config_path} not found')
return
config = Config(config_path)
single_task(config, args.task)
else:
config = Config('./config/default.json')
all_tasks(config)
if __name__ == '__main__':
# 以管理员身份运行
if ctypes.windll.shell32.IsUserAnAdmin():
main()
else:
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, __file__, None, 1)