xtn-tools-pro 1.0.0.2.6__tar.gz → 1.0.0.2.8__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.2.6/xtn_tools_pro.egg-info → xtn-tools-pro-1.0.0.2.8}/PKG-INFO +1 -1
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/setup.py +1 -1
- xtn-tools-pro-1.0.0.2.8/xtn_tools_pro/task_pro/go_fun.py +208 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8/xtn_tools_pro.egg-info}/PKG-INFO +1 -1
- xtn-tools-pro-1.0.0.2.6/xtn_tools_pro/task_pro/go_fun.py +0 -43
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/LICENSE +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/README.md +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/setup.cfg +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/db/MongoDB.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/db/MysqlDB.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/db/RedisDB.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/db/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/proxy/XiaoXiangProxy.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/proxy/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/proxy/proxy.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/task_pro/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/tools.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/__init__.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/crypto.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/file_utils.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/helpers.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/log.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/retry.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/sql.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro/utils/time_utils.py +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro.egg-info/SOURCES.txt +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro.egg-info/dependency_links.txt +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro.egg-info/requires.txt +0 -0
- {xtn-tools-pro-1.0.0.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro.egg-info/top_level.txt +0 -0
@@ -0,0 +1,208 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
# 说明:
|
5
|
+
# 程序说明xxxxxxxxxxxxxxxxxxx
|
6
|
+
# History:
|
7
|
+
# Date Author Version Modification
|
8
|
+
# --------------------------------------------------------------------------------------------------
|
9
|
+
# 2025/1/14 xiatn V00.01.000 新建
|
10
|
+
# --------------------------------------------------------------------------------------------------
|
11
|
+
import time
|
12
|
+
import inspect
|
13
|
+
import requests
|
14
|
+
import threading
|
15
|
+
import multiprocessing
|
16
|
+
import concurrent.futures
|
17
|
+
from multiprocessing import Process
|
18
|
+
|
19
|
+
|
20
|
+
class GoFun:
|
21
|
+
def __init__(self, ini_dict, logger, go_task_function=None):
|
22
|
+
# 读取配置信息
|
23
|
+
host = ini_dict.get('host', '')
|
24
|
+
port = ini_dict.get('port', 0)
|
25
|
+
task = ini_dict.get('task', '')
|
26
|
+
auto = ini_dict.get('auto', '')
|
27
|
+
processes_num = ini_dict.get('processes_num', 0)
|
28
|
+
thread_num = ini_dict.get('thread_num', 0)
|
29
|
+
restart_time = ini_dict.get('restart_time', 0)
|
30
|
+
|
31
|
+
self.__ini_info = {
|
32
|
+
"host": host,
|
33
|
+
"port": port,
|
34
|
+
"task": task,
|
35
|
+
"auto": auto,
|
36
|
+
"processes_num": processes_num,
|
37
|
+
"thread_num": thread_num,
|
38
|
+
"restart_time": restart_time,
|
39
|
+
}
|
40
|
+
|
41
|
+
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"]:
|
43
|
+
raise Exception(f"ini_dict 配置 {server_k} 不存在")
|
44
|
+
|
45
|
+
if port:
|
46
|
+
task_host = f"http://{host}:{port}"
|
47
|
+
else:
|
48
|
+
task_host = f"http://{host}"
|
49
|
+
|
50
|
+
download_url = task_host + "/filter_server/phone/get"
|
51
|
+
upload_url = task_host + "/filter_server/phone/update"
|
52
|
+
external_ip = self.__get_external_ip()
|
53
|
+
|
54
|
+
self.__ini_info["download_url"] = download_url
|
55
|
+
self.__ini_info["upload_url"] = upload_url
|
56
|
+
self.__ini_info["external_ip"] = external_ip
|
57
|
+
|
58
|
+
self.logger = logger
|
59
|
+
|
60
|
+
if not go_task_function:
|
61
|
+
return
|
62
|
+
|
63
|
+
# 共享任务队列
|
64
|
+
download_queue = multiprocessing.Queue()
|
65
|
+
upload_queue = multiprocessing.Queue()
|
66
|
+
download_task_process = multiprocessing.Process(target=self._download_and_upload_task,
|
67
|
+
args=(download_queue, upload_queue, self.__ini_info, logger))
|
68
|
+
download_task_process.start()
|
69
|
+
|
70
|
+
# 根据配置启动任务
|
71
|
+
if go_task_function:
|
72
|
+
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))
|
75
|
+
go_task_fun_process.start()
|
76
|
+
|
77
|
+
def __get_external_ip(self):
|
78
|
+
"""
|
79
|
+
获取当前网络ip
|
80
|
+
:return:
|
81
|
+
"""
|
82
|
+
while True:
|
83
|
+
try:
|
84
|
+
rp = requests.get('https://httpbin.org/ip')
|
85
|
+
rp_json = rp.json()
|
86
|
+
print(f"当前网络ip --> {rp_json}")
|
87
|
+
return rp_json['origin']
|
88
|
+
except Exception as e:
|
89
|
+
pass
|
90
|
+
|
91
|
+
def _download_and_upload_task(self, download_queue, upload_queue, ini_info, logger):
|
92
|
+
"""
|
93
|
+
使用两个线程 打开 获取任务、回写任务
|
94
|
+
:param queue:
|
95
|
+
:return:
|
96
|
+
"""
|
97
|
+
caller = inspect.stack()[1] # 获取调用者的调用栈信息
|
98
|
+
caller_name = caller.function # 获取调用者的函数名
|
99
|
+
caller_class = caller.frame.f_locals.get('self', None) # 获取调用者的类实例
|
100
|
+
if caller_name != "run" or caller_class is None:
|
101
|
+
raise Exception("错误调用")
|
102
|
+
thread_download_task = threading.Thread(target=self.__download_task, args=(download_queue, ini_info, logger))
|
103
|
+
thread_download_task.start()
|
104
|
+
thread_upload_task = threading.Thread(target=self.__upload_task, args=(upload_queue, ini_info, logger))
|
105
|
+
thread_upload_task.start()
|
106
|
+
|
107
|
+
def __download_task(self, download_queue, ini_info, logger):
|
108
|
+
"""
|
109
|
+
获取任务
|
110
|
+
:param queue:
|
111
|
+
:return:
|
112
|
+
"""
|
113
|
+
download_url = ini_info["download_url"]
|
114
|
+
external_ip = ini_info["external_ip"]
|
115
|
+
auto = ini_info["auto"]
|
116
|
+
task = ini_info["task"]
|
117
|
+
headers = {"Authorization": auto}
|
118
|
+
params = {"taskType": task}
|
119
|
+
while True:
|
120
|
+
qsize = download_queue.qsize()
|
121
|
+
logger.info(f"获取任务,当前队列任务数:{qsize}")
|
122
|
+
if download_queue.qsize() >= 10:
|
123
|
+
time.sleep(2)
|
124
|
+
continue
|
125
|
+
resp = requests.get(download_url, headers=headers, params=params, timeout=5)
|
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):
|
133
|
+
"""
|
134
|
+
回写任务
|
135
|
+
:return:
|
136
|
+
"""
|
137
|
+
upload_url = ini_info["upload_url"]
|
138
|
+
external_ip = ini_info["external_ip"]
|
139
|
+
auto = ini_info["auto"]
|
140
|
+
task = ini_info["task"]
|
141
|
+
headers = {"Authorization": auto}
|
142
|
+
params = {"taskType": task}
|
143
|
+
while True:
|
144
|
+
qsize = queue.qsize()
|
145
|
+
print("回写任务", qsize)
|
146
|
+
time.sleep(1)
|
147
|
+
|
148
|
+
def _go_task_fun_task(self, download_queue, upload_queue, ini_info, go_task_function, logger):
|
149
|
+
"""
|
150
|
+
单函数,根据配置启动程序
|
151
|
+
:param queue:
|
152
|
+
:return:
|
153
|
+
"""
|
154
|
+
caller = inspect.stack()[1] # 获取调用者的调用栈信息
|
155
|
+
caller_name = caller.function # 获取调用者的函数名
|
156
|
+
caller_class = caller.frame.f_locals.get('self', None) # 获取调用者的类实例
|
157
|
+
if caller_name != "run" or caller_class is None:
|
158
|
+
raise Exception("错误调用")
|
159
|
+
|
160
|
+
processes_num = ini_info["processes_num"]
|
161
|
+
thread_num = ini_info["thread_num"]
|
162
|
+
restart_time = ini_info["restart_time"]
|
163
|
+
|
164
|
+
processes_num = 1 if processes_num <= 0 else processes_num
|
165
|
+
thread_num = 1 if thread_num <= 0 else thread_num
|
166
|
+
|
167
|
+
go_task_fun_cnt = 0
|
168
|
+
processes_start_list = []
|
169
|
+
while True:
|
170
|
+
try:
|
171
|
+
if not processes_start_list:
|
172
|
+
go_task_fun_cnt += 1
|
173
|
+
logger.info(
|
174
|
+
f"第{go_task_fun_cnt}次,进程数:{processes_num},线程数:{thread_num},等待{restart_time}秒强制下一次")
|
175
|
+
for i in range(processes_num):
|
176
|
+
p = Process(target=self._run_with_timeout,
|
177
|
+
args=(download_queue, upload_queue, thread_num, go_task_function))
|
178
|
+
processes_start_list.append(p)
|
179
|
+
p.start()
|
180
|
+
|
181
|
+
if not restart_time:
|
182
|
+
# 一直执行 不退出
|
183
|
+
continue
|
184
|
+
|
185
|
+
time.sleep(restart_time)
|
186
|
+
# 关闭所有进程
|
187
|
+
for p in processes_start_list:
|
188
|
+
p.terminate()
|
189
|
+
p.join() # 等待进程确实结束
|
190
|
+
processes_start_list = []
|
191
|
+
|
192
|
+
except Exception as e:
|
193
|
+
pass
|
194
|
+
|
195
|
+
def _run_with_timeout(self, download_queue, upload_queue, thread_num, go_task_function):
|
196
|
+
caller = inspect.stack()[1] # 获取调用者的调用栈信息
|
197
|
+
caller_name = caller.function # 获取调用者的函数名
|
198
|
+
caller_class = caller.frame.f_locals.get('self', None) # 获取调用者的类实例
|
199
|
+
if caller_name != "run" or caller_class is None:
|
200
|
+
raise Exception("错误调用")
|
201
|
+
|
202
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_num) as executor:
|
203
|
+
# 提交10个函数到线程池中执行
|
204
|
+
futures = [executor.submit(go_task_function, download_queue, upload_queue) for _ in range(thread_num)]
|
205
|
+
|
206
|
+
# 等待所有线程完成
|
207
|
+
for future in concurrent.futures.as_completed(futures):
|
208
|
+
future.result()
|
@@ -1,43 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
# 说明:
|
5
|
-
# 程序说明xxxxxxxxxxxxxxxxxxx
|
6
|
-
# History:
|
7
|
-
# Date Author Version Modification
|
8
|
-
# --------------------------------------------------------------------------------------------------
|
9
|
-
# 2025/1/14 xiatn V00.01.000 新建
|
10
|
-
# --------------------------------------------------------------------------------------------------
|
11
|
-
import os
|
12
|
-
import configparser
|
13
|
-
from xtn_tools_pro.utils.file_utils import check_file_exists
|
14
|
-
|
15
|
-
|
16
|
-
class GoFun:
|
17
|
-
def __init__(self, ini_file=""):
|
18
|
-
if not ini_file:
|
19
|
-
ini_current_dir = os.getcwd()
|
20
|
-
ini_file = os.path.join(ini_current_dir, "st.ini")
|
21
|
-
if not check_file_exists(ini_file):
|
22
|
-
raise Exception("st.ini 配置文件不存在,请在当前文件夹中新建该配置文件")
|
23
|
-
|
24
|
-
# 读取配置信息
|
25
|
-
config = configparser.ConfigParser()
|
26
|
-
config.read(ini_file)
|
27
|
-
server_host = config.get('server', 'host')
|
28
|
-
server_port = config.get('server', 'port')
|
29
|
-
server_task = config.get('server', 'task')
|
30
|
-
server_auto = config.get('server', 'auto')
|
31
|
-
|
32
|
-
print(server_host, server_port, server_task)
|
33
|
-
if server_port:
|
34
|
-
task_host = f"http://{server_host}:{server_port}"
|
35
|
-
else:
|
36
|
-
task_host = f"http://{server_host}"
|
37
|
-
|
38
|
-
download_url = task_host + "/filter_server/phone/get"
|
39
|
-
upload_url = task_host + "/filter_server/phone/update"
|
40
|
-
|
41
|
-
print(server_auto)
|
42
|
-
print(download_url)
|
43
|
-
print(upload_url)
|
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.2.6 → xtn-tools-pro-1.0.0.2.8}/xtn_tools_pro.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|