-
Notifications
You must be signed in to change notification settings - Fork 121
/
main.py
163 lines (146 loc) · 5.42 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
from _deprecated.initialize import execute
from core.constant import USER_DEFAULT_DICT as UDD
# 主程序
from core.pcr_config import trace_exception_for_debug
from core.usercentre import AutomatorRecorder, list_all_users
def RunFirstTime():
users = list_all_users(0)
for acc in users:
Restart(acc)
execute(False, 3)
def RunContinue():
execute(True, 3)
def CheckState():
users = list_all_users(0)
for acc in users:
AR = AutomatorRecorder(acc)
uj = AR.getuser()
print("USER: ", acc, " TASK: ", "NONE" if uj["taskfile"] == "" else uj["taskfile"], "STATUS ", end="")
rs = AR.get_run_status()
if rs["error"] is None:
if rs["finished"]:
print("FINISHED.")
else:
print("CURRENT: ", rs["current"])
else:
print("ERROR: ", rs["error"])
def CheckTuitu():
users = list_all_users(0)
for acc in users:
AR = AutomatorRecorder(acc)
ts = AR.get("tuitu_status", UDD["tuitu_status"])
if ts['max'] is not None:
print("USER: ", acc, " Normal: ", ts['max'])
def CheckStateReturn():
users = list_all_users(0)
acc_task_info = []
for acc in users:
AR = AutomatorRecorder(acc)
uj = AR.getuser()
acc_task_tmpinfo = "账号:%s 任务:%s 状态:" % (acc, "NONE" if uj["taskfile"] == "" else uj["taskfile"])
rs = AR.get_run_status()
if rs["error"] is None:
if rs["finished"]:
acc_task_tmpinfo = acc_task_tmpinfo + "FINISHED."
else:
acc_task_tmpinfo = acc_task_tmpinfo + "CURRENT:%s" % rs["current"]
else:
acc_task_tmpinfo = acc_task_tmpinfo + "ERROR:%s" % rs["error"]
acc_task_info.append(acc_task_tmpinfo)
acc_task_info.append('\n')
acc_task_info = ''.join(acc_task_info).replace(',', '\n').replace("'", '')
return acc_task_info
def ClearError(acc):
"""
重启某用户的错误让他继续跑
:param acc: 要处理的用户名字
"""
AR = AutomatorRecorder(acc)
rs = AR.get_run_status()
rs["error"] = None
rs["finished"] = False
AR.set_run_status(rs)
def Restart(acc):
"""
重置某一个用户,让它重头跑
Restart之后,再次调用RunContinue时,该用户会从头跑
:param acc: 要处理的用户的名字
"""
AR = AutomatorRecorder(acc)
rs = AR.get_run_status()
rs["error"] = None
rs["finished"] = False
rs["current"] = "..."
AR.set_run_status(rs)
target = "rec/%s.rec" % acc
if os.path.exists(target):
os.remove(target) # 删除行动记录文件
def SetFinished(acc):
"""
设置某一个用户的状态为已经跑完
:param acc: 用户
"""
AR = AutomatorRecorder(acc)
rs = AR.get_run_status()
rs["error"] = None
rs["finished"] = True
rs["current"] = "..."
AR.set_run_status(rs)
if __name__ == '__main__':
print("------------- 用户脚本控制台 ------------")
print("help 查看帮助 exit 退出")
print("By TheAutumnOfRice")
print("----------------------------------------")
print("!! 警告:该控制器已经于2020-08-04停止维护,请使用最新的main_new.py享受“计划” Schedule的运行模式")
print("!! 旧版本可能仍然可以继续使用,但是可能存在与新版本不兼容的地方")
print("!! 该版本将不再支持server酱定时发送状态的功能")
while True:
try:
cmd = input("> ")
cmds = cmd.split(" ")
order = cmds[0]
if order == "exit":
break
elif order == "help":
print("脚本控制帮助")
print("first 所有脚本全部重跑")
print("continue 所有脚本从上次断点开始继续跑")
print("state 显示所有用户的状态")
print("state -tuitu 显示所有用户推图的状态")
print("clear ACCOUNT 清除Account的错误状态让它继续跑")
print("restart ACCOUNT 清除Account的运行记录,让它重新开始")
print("finish ACCOUNT 标记Account已经刷完,不再继续刷")
print("edit 进入用户配置编辑模式")
elif order == "first":
RunFirstTime()
elif order == "continue":
RunContinue()
elif order == "state":
if len(cmds) == 2 and cmds[1] == "-tuitu":
CheckTuitu()
else:
CheckState()
elif order == "clear":
if len(cmds) > 1:
ClearError(cmds[1])
else:
print("需要指定Account")
elif order == "restart":
if len(cmds) > 1:
Restart(cmds[1])
else:
print("需要指定Account")
elif order == "finish":
if len(cmds) > 1:
SetFinished(cmds[1])
else:
print("需要指定Account")
elif order == "edit":
exec(open("_deprecated\\CreateUser.py", "r", encoding="utf-8").read())
else:
print("未知的命令")
except Exception as e:
print("出现错误:", e)
if trace_exception_for_debug:
raise e