This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
159 lines (146 loc) · 4.88 KB
/
main.py
File metadata and controls
159 lines (146 loc) · 4.88 KB
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
import configparser
import time
import start
import random
import sys
import os
def get_file_path(file_name=""):
"""
获取文件绝对路径, 防止在某些情况下报错
:param file_name: 文件名
:return:
"""
return os.path.join(os.path.split(sys.argv[0])[0], file_name)
print(start.to_log("INFO", "程序启动。"))
conf = configparser.ConfigParser()
conf.read(get_file_path("config.ini"), encoding = "utf-8")
userdata = {
"uid":"",
"stoken":"",
"id":""
}
setting = {
"module_id":"",
"t1":"",
"t2":"",
"timeout":""
}
setting["module_id"] = conf.get("Settings", "module_id")
setting["module_id"] = setting["module_id"].replace(" ", "")
setting["module_id"] = setting["module_id"].split(",")
setting["t1"] = conf.get("Settings", "t1")
setting["t2"] = conf.get("Settings", "t2")
setting["timeout"] = conf.get("Settings", "timeout")
timesleep_1 = setting["t1"]
timesleep_2 = setting["t2"]
if timesleep_1 == '' or None:
timesleep_1 = 2
if timesleep_2 == '' or None:
timesleep_2 = 4
timesleep_1 = float(timesleep_1)
timesleep_2 = float(timesleep_2)
result_error = {}
result_exception = {}
def check(i):
if conf.has_option("Cookies", "uid_{0}".format(i)) == False:
return False
elif conf.has_option("Cookies", "stoken_{0}".format(i)) == False:
return False
else:
return True
## 开始操作
i = 1
while True:
userdata["uid"] = conf.get("Cookies", "uid_{0}".format(i))
userdata["stoken"] = conf.get("Cookies", "stoken_{0}".format(i))
userdata["id"] = str(i)
result = start.start(userdata, setting)
if result == "error":
result_error[str(i)] = userdata["uid"]
elif result != "success":
result_exception[str(i)] = userdata["uid"]
i += 1
if check(i) == True:
time.sleep(random.uniform(timesleep_1, timesleep_2))
else:
break
## 检查是否有执行失败的用户
if result_error == {}:
if result_exception == {}:
print(start.to_log("INFO", "所有用户均操作完毕。"))
print(start.to_log("INFO", "程序结束。"))
exit(0)
if result_error != {}:
it = iter(result_error)
while True:
try:
error_id = next(it)
print(start.to_log("WARN", "执行失败的用户:uid_{0} - {1}".format(error_id, result_error[error_id])))
except StopIteration:
break
if result_exception != {}:
it = iter(result_exception)
while True:
try:
exception_id = next(it)
print(start.to_log("WARN", "执行异常的用户:uid_{0} - {1}".format(exception_id, result_exception[exception_id])))
except StopIteration:
break
## 重试执行失败和异常的用户任务
print(start.to_log("INFO", "正在重启执行失败和异常用户的任务。"))
if result_error != {}:
it = iter(result_error)
del_error_id = []
while True:
try:
error_id = next(it)
userdata["uid"] = conf.get("Cookies", "uid_{0}".format(error_id))
userdata["stoken"] = conf.get("Cookies", "stoken_{0}".format(error_id))
userdata["id"] = error_id
result = start.start(userdata, setting)
if result == "success":
del_error_id.append(error_id)
except StopIteration:
if del_error_id != []:
for id in del_error_id:
del result_error[id]
break
if result_exception != {}:
it = iter(result_exception)
del_exception_id = []
while True:
try:
exception_id = next(it)
userdata["uid"] = conf.get("Cookies", "uid_{0}".format(exception_id))
userdata["stoken"] = conf.get("Cookies", "stoken_{0}".format(exception_id))
result = start.start(userdata, setting)
if result == "success":
del_exception_id.append(exception_id)
except StopIteration:
if del_exception_id != []:
for id in del_exception_id:
del result_exception[id]
break
## 再次检查执行失败的用户
if result_error == {}:
if result_exception == {}:
print(start.to_log("INFO", "所有用户均操作完毕。"))
print(start.to_log("INFO", "程序结束。"))
exit(0)
if result_error != {}:
it = iter(result_error)
while True:
try:
error_id = next(it)
print(start.to_log("WARN", "依旧执行失败的用户:uid_{0} - {1}".format(error_id, result_error[error_id])))
except StopIteration:
break
if result_exception != {}:
it = iter(result_exception)
while True:
try:
exception_id = next(it)
print(start.to_log("WARN", "依旧执行异常的用户:uid_{0} - {1}".format(exception_id, result_exception[exception_id])))
except StopIteration:
break
print(start.to_log("INFO", "程序结束。"))