xtn-tools-pro 1.0.0.3.0__py3-none-any.whl → 1.0.0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xtn-tools-pro might be problematic. Click here for more details.

@@ -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, self.__ini_info, logger))
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, self.__ini_info,
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
  """
@@ -119,7 +132,7 @@ class GoFun:
119
132
  while True:
120
133
  qsize = download_queue.qsize()
121
134
  logger.info(f"获取任务,当前队列任务数:{qsize}")
122
- if download_queue.qsize() >= 10:
135
+ if qsize >= 10:
123
136
  time.sleep(2)
124
137
  continue
125
138
  resp = requests.get(download_url, headers=headers, params=params, timeout=5)
@@ -129,7 +142,7 @@ class GoFun:
129
142
  download_queue.put(task_item)
130
143
  logger.info(f"成功获取任务个数:{len(result_list)}")
131
144
 
132
- def __upload_task(self, queue, ini_info, logger):
145
+ def __upload_task(self, upload_queue, ini_info, logger):
133
146
  """
134
147
  回写任务
135
148
  :return:
@@ -142,7 +155,7 @@ class GoFun:
142
155
  params = {"taskType": task}
143
156
  while True:
144
157
  # 判断队列是否有值
145
- empty = queue.empty()
158
+ empty = upload_queue.empty()
146
159
  if empty:
147
160
  time.sleep(2)
148
161
  continue
@@ -151,7 +164,7 @@ class GoFun:
151
164
  result_list = []
152
165
  try:
153
166
  while True:
154
- task_item = queue.get_nowait()
167
+ task_item = upload_queue.get_nowait()
155
168
  taskNo = task_item["taskNo"]
156
169
  phone = task_item["phone"]
157
170
  isRegistered = task_item["isRegistered"]
@@ -177,7 +190,43 @@ class GoFun:
177
190
  except Exception as e:
178
191
  logger.critical(f"回写异常,{len(result_list)},{e}")
179
192
 
180
- def _go_task_fun_task(self, download_queue, upload_queue, ini_info, go_task_function, logger):
193
+ def __update_proxy(self, proxies_dict, ini_info, logger):
194
+ """
195
+ 更新代理
196
+ :return:
197
+ """
198
+ update_proxy_url = ini_info["update_proxy_url"]
199
+ auto = ini_info["auto"]
200
+ update_proxies_time = ini_info["update_proxies_time"]
201
+ headers = {"Authorization": auto}
202
+
203
+ while True:
204
+ try:
205
+ if not proxies_dict.get("status"):
206
+ resp = requests.get(update_proxy_url, headers=headers, timeout=5)
207
+ json_data = resp.json()
208
+ status_code = resp.status_code
209
+ result_list = json_data.get("result", [])
210
+ if not result_list or status_code != 200:
211
+ logger.critical(f"获取代理响应异常:{status_code} {len(result_list)} {json_data}")
212
+ time.sleep(2)
213
+
214
+ proxies_dict['http'] = 'http://' + random.choice(result_list)
215
+ proxies_dict['https'] = 'http://' + random.choice(result_list)
216
+ proxies_dict['status'] = True
217
+ logger.info(f"成功获取代理:{proxies_dict}")
218
+
219
+ if not update_proxies_time:
220
+ # 一直执行 不退出
221
+ continue
222
+
223
+ time.sleep(update_proxies_time)
224
+ proxies_dict['status'] = False
225
+ except Exception as e:
226
+ logger.critical(f"获取代理请求异常:{e}")
227
+ time.sleep(2)
228
+
229
+ def _go_task_fun_task(self, download_queue, upload_queue, proxies_dict, ini_info, go_task_function, logger):
181
230
  """
182
231
  单函数,根据配置启动程序
183
232
  :param queue:
@@ -206,7 +255,7 @@ class GoFun:
206
255
  f"第{go_task_fun_cnt}次,进程数:{processes_num},线程数:{thread_num},等待{restart_time}秒强制下一次")
207
256
  for i in range(processes_num):
208
257
  p = Process(target=self._run_with_timeout,
209
- args=(download_queue, upload_queue, thread_num, go_task_function))
258
+ args=(download_queue, upload_queue, proxies_dict, thread_num, go_task_function))
210
259
  processes_start_list.append(p)
211
260
  p.start()
212
261
 
@@ -224,7 +273,7 @@ class GoFun:
224
273
  except Exception as e:
225
274
  pass
226
275
 
227
- def _run_with_timeout(self, download_queue, upload_queue, thread_num, go_task_function):
276
+ def _run_with_timeout(self, download_queue, upload_queue, proxies_dict, thread_num, go_task_function):
228
277
  caller = inspect.stack()[1] # 获取调用者的调用栈信息
229
278
  caller_name = caller.function # 获取调用者的函数名
230
279
  caller_class = caller.frame.f_locals.get('self', None) # 获取调用者的类实例
@@ -233,7 +282,8 @@ class GoFun:
233
282
 
234
283
  with concurrent.futures.ThreadPoolExecutor(max_workers=thread_num) as executor:
235
284
  # 提交10个函数到线程池中执行
236
- futures = [executor.submit(go_task_function, download_queue, upload_queue) for _ in range(thread_num)]
285
+ futures = [executor.submit(go_task_function, download_queue, upload_queue, proxies_dict) for _ in
286
+ range(thread_num)]
237
287
 
238
288
  # 等待所有线程完成
239
289
  for future in concurrent.futures.as_completed(futures):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xtn-tools-pro
3
- Version: 1.0.0.3.0
3
+ Version: 1.0.0.3.2
4
4
  Summary: xtn 开发工具
5
5
  Author: xtn
6
6
  Author-email: czw011122@gmail.com
@@ -10,7 +10,7 @@ xtn_tools_pro/proxy/XiaoXiangProxy.py,sha256=45SsMZDc-3Ta4THX38vScjaeRBJSp420AJw
10
10
  xtn_tools_pro/proxy/__init__.py,sha256=WRwh6s2lruMu5buh0ejo9EK54kWT_VQhCsFGNFAmcyo,418
11
11
  xtn_tools_pro/proxy/proxy.py,sha256=No6E1pFY5yx2F4976pXPrLtq-QEVp79KupzcufjSN58,8703
12
12
  xtn_tools_pro/task_pro/__init__.py,sha256=nK3U47hWwE1H875ieEToH9r-jzXHS-PXk8cDstOvRE8,418
13
- xtn_tools_pro/task_pro/go_fun.py,sha256=GCIfckuNR47uxRvoKCBBlne6M7nXzVuMNSHhdodS_5g,9817
13
+ xtn_tools_pro/task_pro/go_fun.py,sha256=KZ6whWxngzvXnq-rej9MMMToVYl8FM6WqpJpa-LkqXk,12200
14
14
  xtn_tools_pro/utils/__init__.py,sha256=I1_n_NP23F2lBqlF4EOlnOdLYxM8M4pbn63UhJN1hRE,418
15
15
  xtn_tools_pro/utils/crypto.py,sha256=RZ5AET4udlraACWMeNF-17JiZ2R6Ahb47_j4tjkV7LE,3190
16
16
  xtn_tools_pro/utils/file_utils.py,sha256=VfdIxog4s1UW5NpKkCvQsUs9qHjLoNCnstZbnftkT4w,2046
@@ -19,8 +19,8 @@ xtn_tools_pro/utils/log.py,sha256=XZChGrKWgAz42o_gFi_d7DL28svF1OvAw7NS_xkIgnQ,10
19
19
  xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,1657
20
20
  xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
21
21
  xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
22
- xtn_tools_pro-1.0.0.3.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- xtn_tools_pro-1.0.0.3.0.dist-info/METADATA,sha256=4bEX_P5pv8elCZsoRSRHtpT3TuGV3NBR8wjjgArF6Zw,455
24
- xtn_tools_pro-1.0.0.3.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
25
- xtn_tools_pro-1.0.0.3.0.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
26
- xtn_tools_pro-1.0.0.3.0.dist-info/RECORD,,
22
+ xtn_tools_pro-1.0.0.3.2.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ xtn_tools_pro-1.0.0.3.2.dist-info/METADATA,sha256=Y2ahGfTRguKLz4GMNNukWoRcSQYAtio5Dnf7t9tSkSE,455
24
+ xtn_tools_pro-1.0.0.3.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
25
+ xtn_tools_pro-1.0.0.3.2.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
26
+ xtn_tools_pro-1.0.0.3.2.dist-info/RECORD,,