xtn-tools-pro 1.0.0.3.1__tar.gz → 1.0.0.3.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {xtn-tools-pro-1.0.0.3.1/xtn_tools_pro.egg-info → xtn-tools-pro-1.0.0.3.3}/PKG-INFO +1 -1
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/setup.py +1 -1
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/task_pro/go_fun.py +77 -23
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3/xtn_tools_pro.egg-info}/PKG-INFO +1 -1
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/LICENSE +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/README.md +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/setup.cfg +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/db/MongoDB.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/db/MysqlDB.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/db/RedisDB.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/db/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/proxy/XiaoXiangProxy.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/proxy/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/proxy/proxy.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/task_pro/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/tools.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/crypto.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/file_utils.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/helpers.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/log.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/retry.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/sql.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro/utils/time_utils.py +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro.egg-info/SOURCES.txt +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro.egg-info/dependency_links.txt +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro.egg-info/requires.txt +0 -0
- {xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro.egg-info/top_level.txt +0 -0
@@ -9,6 +9,7 @@
|
|
9
9
|
# 2025/1/14 xiatn V00.01.000 新建
|
10
10
|
# --------------------------------------------------------------------------------------------------
|
11
11
|
import time
|
12
|
+
import random
|
12
13
|
import inspect
|
13
14
|
import requests
|
14
15
|
import threading
|
@@ -27,6 +28,7 @@ class GoFun:
|
|
27
28
|
processes_num = ini_dict.get('processes_num', 0)
|
28
29
|
thread_num = ini_dict.get('thread_num', 0)
|
29
30
|
restart_time = ini_dict.get('restart_time', 0)
|
31
|
+
update_proxies_time = ini_dict.get('update_proxies_time', 0)
|
30
32
|
|
31
33
|
self.__ini_info = {
|
32
34
|
"host": host,
|
@@ -36,10 +38,12 @@ class GoFun:
|
|
36
38
|
"processes_num": processes_num,
|
37
39
|
"thread_num": thread_num,
|
38
40
|
"restart_time": restart_time,
|
41
|
+
"update_proxies_time": update_proxies_time,
|
39
42
|
}
|
40
43
|
|
41
44
|
for server_k, server_v in self.__ini_info.items():
|
42
|
-
if not server_v and server_k not in ["port", "processes_num", "thread_num", "restart_time"
|
45
|
+
if not server_v and server_k not in ["port", "processes_num", "thread_num", "restart_time",
|
46
|
+
"update_proxies_time"]:
|
43
47
|
raise Exception(f"ini_dict 配置 {server_k} 不存在")
|
44
48
|
|
45
49
|
if port:
|
@@ -49,10 +53,12 @@ class GoFun:
|
|
49
53
|
|
50
54
|
download_url = task_host + "/filter_server/phone/get"
|
51
55
|
upload_url = task_host + "/filter_server/phone/update"
|
56
|
+
update_proxy_url = task_host + f"/filter_server/proxy/random/get?taskType={task}&limit=1"
|
52
57
|
external_ip = self.__get_external_ip()
|
53
58
|
|
54
59
|
self.__ini_info["download_url"] = download_url
|
55
60
|
self.__ini_info["upload_url"] = upload_url
|
61
|
+
self.__ini_info["update_proxy_url"] = update_proxy_url
|
56
62
|
self.__ini_info["external_ip"] = external_ip
|
57
63
|
|
58
64
|
self.logger = logger
|
@@ -61,19 +67,24 @@ class GoFun:
|
|
61
67
|
return
|
62
68
|
|
63
69
|
# 共享任务队列
|
70
|
+
manager = multiprocessing.Manager()
|
64
71
|
download_queue = multiprocessing.Queue()
|
65
72
|
upload_queue = multiprocessing.Queue()
|
73
|
+
proxies_dict = manager.dict()
|
66
74
|
download_task_process = multiprocessing.Process(target=self._download_and_upload_task,
|
67
|
-
args=(download_queue, upload_queue,
|
75
|
+
args=(download_queue, upload_queue, proxies_dict,
|
76
|
+
self.__ini_info, logger))
|
68
77
|
download_task_process.start()
|
69
78
|
|
70
79
|
# 根据配置启动任务
|
71
80
|
if go_task_function:
|
72
81
|
go_task_fun_process = multiprocessing.Process(target=self._go_task_fun_task,
|
73
|
-
args=(download_queue, upload_queue,
|
74
|
-
go_task_function, logger))
|
82
|
+
args=(download_queue, upload_queue, proxies_dict,
|
83
|
+
self.__ini_info, go_task_function, logger))
|
75
84
|
go_task_fun_process.start()
|
76
85
|
|
86
|
+
download_task_process.join()
|
87
|
+
|
77
88
|
def __get_external_ip(self):
|
78
89
|
"""
|
79
90
|
获取当前网络ip
|
@@ -88,7 +99,7 @@ class GoFun:
|
|
88
99
|
except Exception as e:
|
89
100
|
pass
|
90
101
|
|
91
|
-
def _download_and_upload_task(self, download_queue, upload_queue, ini_info, logger):
|
102
|
+
def _download_and_upload_task(self, download_queue, upload_queue, proxies_dict, ini_info, logger):
|
92
103
|
"""
|
93
104
|
使用两个线程 打开 获取任务、回写任务
|
94
105
|
:param queue:
|
@@ -103,6 +114,8 @@ class GoFun:
|
|
103
114
|
thread_download_task.start()
|
104
115
|
thread_upload_task = threading.Thread(target=self.__upload_task, args=(upload_queue, ini_info, logger))
|
105
116
|
thread_upload_task.start()
|
117
|
+
thread_update_proxy = threading.Thread(target=self.__update_proxy, args=(proxies_dict, ini_info, logger))
|
118
|
+
thread_update_proxy.start()
|
106
119
|
|
107
120
|
def __download_task(self, download_queue, ini_info, logger):
|
108
121
|
"""
|
@@ -117,19 +130,23 @@ class GoFun:
|
|
117
130
|
headers = {"Authorization": auto}
|
118
131
|
params = {"taskType": task}
|
119
132
|
while True:
|
120
|
-
|
121
|
-
|
122
|
-
|
133
|
+
try:
|
134
|
+
qsize = download_queue.qsize()
|
135
|
+
logger.info(f"获取任务,当前队列任务数:{qsize}")
|
136
|
+
if qsize >= 10:
|
137
|
+
time.sleep(2)
|
138
|
+
continue
|
139
|
+
resp = requests.get(download_url, headers=headers, params=params, timeout=5)
|
140
|
+
json_data = resp.json()
|
141
|
+
result_list = json_data.get("result", [])
|
142
|
+
for task_item in result_list:
|
143
|
+
download_queue.put(task_item)
|
144
|
+
logger.info(f"成功获取任务个数:{len(result_list)}")
|
145
|
+
except Exception as e:
|
146
|
+
logger.critical(f"获取任务请求异常:{e}")
|
123
147
|
time.sleep(2)
|
124
|
-
|
125
|
-
|
126
|
-
json_data = resp.json()
|
127
|
-
result_list = json_data.get("result", [])
|
128
|
-
for task_item in result_list:
|
129
|
-
download_queue.put(task_item)
|
130
|
-
logger.info(f"成功获取任务个数:{len(result_list)}")
|
131
|
-
|
132
|
-
def __upload_task(self, queue, ini_info, logger):
|
148
|
+
|
149
|
+
def __upload_task(self, upload_queue, ini_info, logger):
|
133
150
|
"""
|
134
151
|
回写任务
|
135
152
|
:return:
|
@@ -142,7 +159,7 @@ class GoFun:
|
|
142
159
|
params = {"taskType": task}
|
143
160
|
while True:
|
144
161
|
# 判断队列是否有值
|
145
|
-
empty =
|
162
|
+
empty = upload_queue.empty()
|
146
163
|
if empty:
|
147
164
|
time.sleep(2)
|
148
165
|
continue
|
@@ -151,7 +168,7 @@ class GoFun:
|
|
151
168
|
result_list = []
|
152
169
|
try:
|
153
170
|
while True:
|
154
|
-
task_item =
|
171
|
+
task_item = upload_queue.get_nowait()
|
155
172
|
taskNo = task_item["taskNo"]
|
156
173
|
phone = task_item["phone"]
|
157
174
|
isRegistered = task_item["isRegistered"]
|
@@ -177,7 +194,43 @@ class GoFun:
|
|
177
194
|
except Exception as e:
|
178
195
|
logger.critical(f"回写异常,{len(result_list)},{e}")
|
179
196
|
|
180
|
-
def
|
197
|
+
def __update_proxy(self, proxies_dict, ini_info, logger):
|
198
|
+
"""
|
199
|
+
更新代理
|
200
|
+
:return:
|
201
|
+
"""
|
202
|
+
update_proxy_url = ini_info["update_proxy_url"]
|
203
|
+
auto = ini_info["auto"]
|
204
|
+
update_proxies_time = ini_info["update_proxies_time"]
|
205
|
+
headers = {"Authorization": auto}
|
206
|
+
|
207
|
+
while True:
|
208
|
+
try:
|
209
|
+
if not proxies_dict.get("status"):
|
210
|
+
resp = requests.get(update_proxy_url, headers=headers, timeout=5)
|
211
|
+
json_data = resp.json()
|
212
|
+
status_code = resp.status_code
|
213
|
+
result_list = json_data.get("result", [])
|
214
|
+
if not result_list or status_code != 200:
|
215
|
+
logger.critical(f"获取代理响应异常:{status_code} {len(result_list)} {json_data}")
|
216
|
+
time.sleep(2)
|
217
|
+
|
218
|
+
proxies_dict['http'] = 'http://' + random.choice(result_list)
|
219
|
+
proxies_dict['https'] = 'http://' + random.choice(result_list)
|
220
|
+
proxies_dict['status'] = True
|
221
|
+
logger.info(f"成功获取代理:{proxies_dict}")
|
222
|
+
|
223
|
+
if not update_proxies_time:
|
224
|
+
# 一直执行 不退出
|
225
|
+
continue
|
226
|
+
|
227
|
+
time.sleep(update_proxies_time)
|
228
|
+
proxies_dict['status'] = False
|
229
|
+
except Exception as e:
|
230
|
+
logger.critical(f"获取代理请求异常:{e}")
|
231
|
+
time.sleep(2)
|
232
|
+
|
233
|
+
def _go_task_fun_task(self, download_queue, upload_queue, proxies_dict, ini_info, go_task_function, logger):
|
181
234
|
"""
|
182
235
|
单函数,根据配置启动程序
|
183
236
|
:param queue:
|
@@ -206,7 +259,7 @@ class GoFun:
|
|
206
259
|
f"第{go_task_fun_cnt}次,进程数:{processes_num},线程数:{thread_num},等待{restart_time}秒强制下一次")
|
207
260
|
for i in range(processes_num):
|
208
261
|
p = Process(target=self._run_with_timeout,
|
209
|
-
args=(download_queue, upload_queue, thread_num, go_task_function))
|
262
|
+
args=(download_queue, upload_queue, proxies_dict, thread_num, go_task_function))
|
210
263
|
processes_start_list.append(p)
|
211
264
|
p.start()
|
212
265
|
|
@@ -224,7 +277,7 @@ class GoFun:
|
|
224
277
|
except Exception as e:
|
225
278
|
pass
|
226
279
|
|
227
|
-
def _run_with_timeout(self, download_queue, upload_queue, thread_num, go_task_function):
|
280
|
+
def _run_with_timeout(self, download_queue, upload_queue, proxies_dict, thread_num, go_task_function):
|
228
281
|
caller = inspect.stack()[1] # 获取调用者的调用栈信息
|
229
282
|
caller_name = caller.function # 获取调用者的函数名
|
230
283
|
caller_class = caller.frame.f_locals.get('self', None) # 获取调用者的类实例
|
@@ -233,7 +286,8 @@ class GoFun:
|
|
233
286
|
|
234
287
|
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_num) as executor:
|
235
288
|
# 提交10个函数到线程池中执行
|
236
|
-
futures = [executor.submit(go_task_function, download_queue, upload_queue) for _ in
|
289
|
+
futures = [executor.submit(go_task_function, download_queue, upload_queue, proxies_dict) for _ in
|
290
|
+
range(thread_num)]
|
237
291
|
|
238
292
|
# 等待所有线程完成
|
239
293
|
for future in concurrent.futures.as_completed(futures):
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{xtn-tools-pro-1.0.0.3.1 → xtn-tools-pro-1.0.0.3.3}/xtn_tools_pro.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|