isrpa 0.5__py3-none-any.whl → 0.6__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.
isrpa/OCR.py ADDED
@@ -0,0 +1,76 @@
1
+ import base64
2
+ import json
3
+ import requests
4
+ from Node_example.Other.Template_Exception import *
5
+
6
+
7
+ def OCR_frome_image_path(img_path, apiKey, secretKey, code_type=8000, option='vCode'):
8
+ """
9
+ 执行OCR识别请求,将图片进行Base64编码并发送给OCR服务。
10
+
11
+ - img_path: 图片文件路径
12
+ - apiKey: API密钥
13
+ - secretKey: Secret密钥
14
+ - code_type: 验证码类型(如 字符验证码8000,滑块验证9000,点击验证9000)
15
+ - result: OCR服务返回的结果中的 result 字段值
16
+ """
17
+ with open(img_path, 'rb') as image_file:
18
+ encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
19
+ headers = {
20
+ 'Content-Type': 'application/json'
21
+ }
22
+ payload = {
23
+ "code_type": code_type,
24
+ "image": encoded_image,
25
+ "apiKey": apiKey,
26
+ "secretKey": secretKey,
27
+ }
28
+
29
+ # OCR 服务接口
30
+ url = 'https://ai.i-search.com.cn/ocr/v2/'
31
+ response = requests.post(url + option, json=payload, headers=headers)
32
+
33
+ # 解析返回的 JSON 数据
34
+ response_data = json.loads(response.text)
35
+
36
+ # 返回 result 字段的值
37
+ return response_data.get('result')
38
+
39
+
40
+ def OCR_from_image(img, apiKey, secretKey, code_type=8000, option='vCode'):
41
+ """
42
+ 执行OCR识别请求,将图片进行Base64编码并发送给OCR服务。
43
+
44
+ - img: 图片的二进制数据
45
+ - apiKey: API密钥
46
+ - secretKey: Secret密钥
47
+ - code_type: 验证码类型(如 8000)
48
+ - result: OCR服务返回的结果中的 result 字段值
49
+ """
50
+ encoded_image = base64.b64encode(img).decode('utf-8')
51
+ headers = {
52
+ 'Content-Type': 'application/json'
53
+ }
54
+ payload = {
55
+ "code_type": code_type,
56
+ "image": encoded_image,
57
+ "apiKey": apiKey,
58
+ "secretKey": secretKey,
59
+ }
60
+
61
+ # OCR 服务接口
62
+ url = 'https://ai.i-search.com.cn/ocr/v2/'
63
+ response = requests.post(url + option, json=payload, headers=headers)
64
+
65
+ # 解析返回的 JSON 数据
66
+ response_data = json.loads(response.text)
67
+ try:
68
+ result = response_data.get('result')
69
+ except Exception:
70
+ raise 无效参数
71
+ return result
72
+
73
+ from isrpa import utils
74
+ if __name__ == '__main__':
75
+ path = utils.getPath("admin")
76
+ print(path)
isrpa/Template.py ADDED
@@ -0,0 +1,60 @@
1
+ import json
2
+
3
+
4
+ class Template:
5
+ version = "1.0.0"
6
+ author = "isearch"
7
+ date = "2024-12-20"
8
+ desc = "自动化魔术师模板"
9
+
10
+
11
+ class Parameters:
12
+ def __init__(self, data):
13
+ if isinstance(data, str):
14
+ data = json.loads(data)
15
+ self._data = data
16
+ self._convert_to_object(self._data)
17
+
18
+ def _convert_to_object(self, data):
19
+ if isinstance(data, dict):
20
+ for key, value in data.items():
21
+ setattr(self, key, self._wrap(value))
22
+ elif isinstance(data, list):
23
+ for index, value in enumerate(data):
24
+ data[index] = self._wrap(value)
25
+
26
+ def _wrap(self, value):
27
+ if isinstance(value, dict):
28
+ return Parameters(value)
29
+ elif isinstance(value, list):
30
+ return [self._wrap(item) for item in value]
31
+ else:
32
+ return value
33
+
34
+ def __repr__(self):
35
+ return json.dumps(self._data, ensure_ascii=False, indent=4)
36
+
37
+ def __getattr__(self, name):
38
+ if name in self._data:
39
+ return self._data[name]
40
+ raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
41
+
42
+
43
+ class Node:
44
+ def __init__(self, data):
45
+ if isinstance(data, str):
46
+ data = json.loads(data)
47
+ self.main_function = data.get("main_function")
48
+ self.title = data.get("title")
49
+ self.description = data.get("description")
50
+ self.icon = data.get("icon")
51
+ self.node_type = data.get("node_type")
52
+ self.parameters = Parameters(data.get("parameters"))
53
+ self.returns = Parameters(data.get("returns"))
54
+ self.template = Template
55
+ self._data = Parameters(data)
56
+
57
+ def __getattr__(self, name):
58
+ if name in self._data._data:
59
+ return getattr(self._data, name)
60
+ raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
@@ -0,0 +1,30 @@
1
+ class 登录失败(Exception):
2
+ """异常:登录失败"""
3
+
4
+ def __init__(self, message="登录失败,请检查登录步骤"):
5
+ self.message = message
6
+ super().__init__(self.message)
7
+
8
+
9
+ class 文件不存在(Exception):
10
+ """异常:文件不存在"""
11
+
12
+ def __init__(self, message="文件不存在,请检查文件路径"):
13
+ self.message = message
14
+ super().__init__(self.message)
15
+
16
+
17
+ class 等待超时(Exception):
18
+ """异常:等待超时"""
19
+
20
+ def __init__(self, message="等待超时"):
21
+ self.message = message
22
+ super().__init__(self.message)
23
+
24
+
25
+ class 无效参数(Exception):
26
+ """异常:无效参数"""
27
+
28
+ def __init__(self, message="输入参数无效"):
29
+ self.message = message
30
+ super().__init__(self.message)
isrpa/message.py ADDED
@@ -0,0 +1,283 @@
1
+ import json
2
+
3
+ from Node_example.Other.Template_Exception import *
4
+
5
+
6
+ def action_message(page, message="等待用户操作", button_label="确认", button=True, time=180):
7
+ """
8
+ 参数:
9
+ - page: Page - Playwright的页面对象
10
+ - message: 提示文字
11
+ - button_label: 按钮显示的文字
12
+ - button: 按钮是否显示
13
+ - time: 等待时间(秒)
14
+ """
15
+
16
+ js_code = f"""
17
+ (function() {{
18
+ var message = {json.dumps(message)};
19
+ var button = {json.dumps(button)};
20
+ var buttonLabel = {json.dumps(button_label)};
21
+ var time = {time};
22
+
23
+ // 创建消息容器
24
+ var msgContainer = document.createElement('div');
25
+ msgContainer.id = 'action-message-container';
26
+ msgContainer.style.position = 'absolute';
27
+ msgContainer.style.right = '20px';
28
+ msgContainer.style.bottom = '20px';
29
+ msgContainer.style.zIndex = '2147483647';
30
+ msgContainer.style.fontFamily = '"Helvetica Neue", Helvetica, Arial, sans-serif';
31
+ msgContainer.style.cursor = 'move';
32
+ msgContainer.style.minWidth = '280px';
33
+ msgContainer.style.maxWidth = '280px';
34
+
35
+ // 消息框主体
36
+ var messageDiv = document.createElement('div');
37
+ messageDiv.id = 'custom-message';
38
+ messageDiv.style.backgroundColor = 'rgba(255, 255, 255, 0.8)';
39
+ messageDiv.style.color = '#333333';
40
+ messageDiv.style.padding = '16px';
41
+ messageDiv.style.borderRadius = '8px';
42
+ messageDiv.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.15)';
43
+ messageDiv.style.border = '1px solid #eee';
44
+ messageDiv.style.textAlign = 'center'; // 修改为居中对齐
45
+
46
+ // 文字内容
47
+ var textDiv = document.createElement('div');
48
+ textDiv.style.lineHeight = '1.5';
49
+ textDiv.style.marginBottom = '12px';
50
+ textDiv.style.textAlign = 'center'; // 添加居中对齐
51
+ textDiv.innerHTML = message;
52
+ messageDiv.appendChild(textDiv);
53
+
54
+ // 按钮容器
55
+ var actionDiv = document.createElement('div');
56
+ actionDiv.style.display = 'flex';
57
+ actionDiv.style.gap = '8px';
58
+ actionDiv.style.justifyContent = 'center';
59
+
60
+ // 倒计时显示
61
+ var countdownDiv = null;
62
+ if (time > 0) {{
63
+ countdownDiv = document.createElement('div');
64
+ countdownDiv.style.color = '#666';
65
+ countdownDiv.style.fontSize = '12px';
66
+ countdownDiv.style.marginBottom = '8px';
67
+ countdownDiv.innerHTML = `剩余时间:<span style="color:#007bff">${{time}}</span>秒` ;
68
+ messageDiv.insertBefore(countdownDiv, messageDiv.firstChild);
69
+ }}
70
+
71
+ // 操作按钮
72
+ if (button) {{
73
+ var btn = document.createElement('button');
74
+ btn.innerHTML = buttonLabel;
75
+ btn.style.backgroundColor = '#007bff';
76
+ btn.style.color = 'white';
77
+ btn.style.border = 'none';
78
+ btn.style.borderRadius = '4px';
79
+ btn.style.padding = '8px 16px';
80
+ btn.style.cursor = 'pointer';
81
+ btn.style.transition = 'all 0.2s';
82
+ btn.style.fontSize = '14px';
83
+ btn.style.fontWeight = 'bold';
84
+ btn.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
85
+
86
+ btn.onmouseover = function() {{ this.style.opacity = '0.9' }};
87
+ btn.onmouseout = function() {{ this.style.opacity = '1' }};
88
+
89
+ btn.onclick = function() {{
90
+ msgContainer.remove();
91
+ window.customButtonClicked = true;
92
+ }};
93
+ actionDiv.appendChild(btn);
94
+ }}
95
+
96
+ // 倒计时逻辑
97
+ if (time > 0) {{
98
+ var countdownTime = time;
99
+ var countdownInterval = setInterval(function() {{
100
+ countdownTime--;
101
+ countdownDiv.innerHTML = `剩余时间:<span style="color:#007bff">${{countdownTime}}</span>秒`;
102
+ if (countdownTime <= 0) {{
103
+ clearInterval(countdownInterval);
104
+ msgContainer.remove();
105
+ window.customButtonClicked = true;
106
+ }}
107
+ }}, 1000);
108
+ }}
109
+
110
+ // 拖动功能
111
+ var offsetX, offsetY;
112
+ messageDiv.onmousedown = function(e) {{
113
+ offsetX = e.clientX - msgContainer.offsetLeft;
114
+ offsetY = e.clientY - msgContainer.offsetTop;
115
+ document.onmousemove = function(e) {{
116
+ msgContainer.style.left = (e.clientX - offsetX) + 'px';
117
+ msgContainer.style.top = (e.clientY - offsetY) + 'px';
118
+ }};
119
+ document.onmouseup = function() {{
120
+ document.onmousemove = null;
121
+ document.onmouseup = null;
122
+ }};
123
+ }};
124
+
125
+ // 监听页面跳转或刷新时,设置 window.customButtonClicked 为 true
126
+ window.addEventListener('beforeunload', function() {{
127
+ window.customButtonClicked = true;
128
+ }});
129
+
130
+ // 组合元素
131
+ messageDiv.appendChild(actionDiv);
132
+ msgContainer.appendChild(messageDiv);
133
+ document.body.appendChild(msgContainer);
134
+ window.customButtonClicked = false;
135
+ }})();
136
+ """
137
+ page.wait_for_load_state("domcontentloaded")
138
+ page.evaluate(js_code)
139
+ try:
140
+ page.wait_for_function("window.customButtonClicked === true", timeout=time * 1000)
141
+ except Exception:
142
+ raise 等待超时
143
+
144
+
145
+ def info_message(page, current_action="当前执行", message="网页操作"):
146
+ js_code = f"""
147
+ (function() {{
148
+ var currentAction = {json.dumps(current_action)};
149
+ var message = {json.dumps(message)};
150
+
151
+ // 创建消息容器
152
+ var msgContainer = document.createElement('div');
153
+ msgContainer.id = 'info-message-container';
154
+ msgContainer.style.position = 'absolute';
155
+ msgContainer.style.right = '20px';
156
+ msgContainer.style.top = '20px';
157
+ msgContainer.style.zIndex = '2147483646';
158
+ msgContainer.style.fontFamily = '"Helvetica Neue", Helvetica, Arial, sans-serif';
159
+ msgContainer.style.cursor = 'move';
160
+
161
+ // 消息框主体
162
+ var messageDiv = document.createElement('div');
163
+ messageDiv.id = 'info-message';
164
+ messageDiv.style.backgroundColor = 'rgba(255, 255, 255, 0.8)';
165
+ messageDiv.style.color = '#333333';
166
+ messageDiv.style.padding = '16px';
167
+ messageDiv.style.borderRadius = '8px';
168
+ messageDiv.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.15)';
169
+ messageDiv.style.minWidth = '280px';
170
+ messageDiv.style.maxWidth = '280px';
171
+ messageDiv.style.border = '1px solid #eee';
172
+ messageDiv.style.textAlign = 'center'; // 修改为居中对齐
173
+
174
+ // 当前执行操作内容
175
+ var currentActionDiv = document.createElement('div');
176
+ currentActionDiv.style.fontWeight = 'bold';
177
+ currentActionDiv.style.color = '#007bff';
178
+ currentActionDiv.style.marginBottom = '8px';
179
+ currentActionDiv.innerHTML = currentAction;
180
+ messageDiv.appendChild(currentActionDiv);
181
+
182
+ // 文字内容
183
+ var textDiv = document.createElement('div');
184
+ textDiv.style.lineHeight = '1.5';
185
+ textDiv.style.textAlign = 'center'; // 添加居中对齐
186
+ textDiv.innerHTML = message;
187
+ messageDiv.appendChild(textDiv);
188
+
189
+ // 移除现有的 info-message 弹窗
190
+ var existingMessage = document.getElementById('info-message');
191
+ if (existingMessage) {{
192
+ existingMessage.parentElement.remove();
193
+ }}
194
+
195
+ // 拖动功能
196
+ var offsetX, offsetY;
197
+ messageDiv.onmousedown = function(e) {{
198
+ offsetX = e.clientX - msgContainer.offsetLeft;
199
+ offsetY = e.clientY - msgContainer.offsetTop;
200
+ document.onmousemove = function(e) {{
201
+ msgContainer.style.left = (e.clientX - offsetX) + 'px';
202
+ msgContainer.style.top = (e.clientY - offsetY) + 'px';
203
+ }};
204
+ document.onmouseup = function() {{
205
+ document.onmousemove = null;
206
+ document.onmouseup = null;
207
+ }};
208
+ }};
209
+
210
+ // 组合元素
211
+ msgContainer.appendChild(messageDiv);
212
+ document.body.appendChild(msgContainer);
213
+ }})();
214
+ """
215
+ page.wait_for_load_state("domcontentloaded")
216
+ page.evaluate(js_code)
217
+
218
+
219
+ def info_message2(page, current_action="当前执行", message="网页操作"):
220
+ """
221
+ 参数:
222
+ - page: Page - Playwright的页面对象
223
+ - current_action: str - 第一行显示的文字
224
+ - message: str - 第二行显示的文字
225
+ """
226
+
227
+ js_code = f"""
228
+ (function() {{
229
+ var line1 = {json.dumps(current_action)};
230
+ var line2 = {json.dumps(message)};
231
+ // 移除现有的 lyrics-message 弹窗
232
+ var existingMessage = document.getElementById('lyrics-message');
233
+ if (existingMessage) {{
234
+ existingMessage.parentElement.remove();
235
+ }}
236
+
237
+ // 创建字幕
238
+ var msgContainer = document.createElement('div');
239
+ msgContainer.id = 'lyrics-message-container';
240
+ msgContainer.style.position = 'absolute'; // 使用absolute定位
241
+ msgContainer.style.left = '50%'; // 水平居中
242
+ msgContainer.style.bottom = '20px'; // 显示在页面底部
243
+ msgContainer.style.transform = 'translateX(-50%)'; // 水平居中
244
+ msgContainer.style.zIndex = '2147483647'; // 设置最上层
245
+ msgContainer.style.fontFamily = '"Helvetica Neue", Helvetica, Arial, sans-serif';
246
+ msgContainer.style.pointerEvents = 'none'; // 防止影响页面操作
247
+
248
+ // 创建消息框主体
249
+ var messageDiv = document.createElement('div');
250
+ messageDiv.id = 'lyrics-message';
251
+ messageDiv.style.backgroundColor = 'transparent'; // 设置背景透明
252
+ messageDiv.style.color = '#ffffff';
253
+ messageDiv.style.padding = '8px 16px';
254
+ messageDiv.style.borderRadius = '8px';
255
+ messageDiv.style.textAlign = 'center';
256
+
257
+ // 第一行文字,使用蓝色
258
+ var textDiv1 = document.createElement('div');
259
+ textDiv1.style.fontSize = '20px';
260
+ textDiv1.style.fontWeight = 'bold';
261
+ textDiv1.style.marginBottom = '4px';
262
+ textDiv1.style.color = '#4a90e2'; // 第一行字体颜色为蓝色
263
+ textDiv1.innerHTML = line1;
264
+ messageDiv.appendChild(textDiv1);
265
+
266
+ // 第二行文字,使用深灰色
267
+ var textDiv2 = document.createElement('div');
268
+ textDiv2.style.fontSize = '18px';
269
+ textDiv2.style.lineHeight = '1.5';
270
+ textDiv2.style.color = '#7f8c8d'; // 第二行字体颜色为深灰色
271
+ textDiv2.innerHTML = line2;
272
+ messageDiv.appendChild(textDiv2);
273
+
274
+ // 组合元素并添加到页面
275
+ msgContainer.appendChild(messageDiv);
276
+ document.body.appendChild(msgContainer);
277
+ }})();
278
+ """
279
+
280
+ # 等待页面加载完成
281
+ page.wait_for_load_state("domcontentloaded")
282
+ # 执行 JS 代码
283
+ page.evaluate(js_code)
isrpa/utils.py CHANGED
@@ -50,7 +50,7 @@ def upload_file(file_path,dic_path,port:str):
50
50
  headers = {
51
51
  'Content-Type': 'application/json', # 说明请求体是 JSON 格式
52
52
  }
53
- cmd_str = "proxy_manager_cli upload --port "+port + " --localfile "+ file_path + " --destfile" +dic_path
53
+ cmd_str = "/isearch/magicautoproxy/proxy_manager_cli upload --port "+port + " --localfile "+ file_path + " --destfile" +dic_path
54
54
  # 请求体的数据
55
55
  data = {
56
56
  'cmd_str': cmd_str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: isrpa
3
- Version: 0.5
3
+ Version: 0.6
4
4
  Summary: isrpa package
5
5
  Home-page: https://github.com/yourusername/mypackage
6
6
  Author: ysq
@@ -0,0 +1,10 @@
1
+ isrpa/OCR.py,sha256=fbBIcUiRoMVn_Yk7-I0MnuHNCtQdaKgRwIMhzGge3nc,2326
2
+ isrpa/Template.py,sha256=UP1uovLvJzXEPGo_hzLrIYOu3vZP8Cf6m3G2hGzQ6XA,1958
3
+ isrpa/Template_Exception.py,sha256=FdarwIMF8qHpcTYoEKF7Ru-pcKnt9NIoyuCSobKEphw,827
4
+ isrpa/__init__.py,sha256=pG-YPVG0gJIJ6s4xcAz9S_CnUxpUcz33wl9eNUSgxGk,20
5
+ isrpa/message.py,sha256=salmKkbxbVic7HlbHJQ1x9JhjjbQwJsvRa4tZ2JPY4M,11347
6
+ isrpa/utils.py,sha256=bmcEvxfLhrWOFGUXpBSSsGlfD8qmJ-lCm8VHoYpEPEY,50851
7
+ isrpa-0.6.dist-info/METADATA,sha256=DC-mWOVBff868CiIJByepZ8w2D_3Z8wU4rAId9bHIuY,457
8
+ isrpa-0.6.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
9
+ isrpa-0.6.dist-info/top_level.txt,sha256=J5HJbtR2WAeKnW1rrpkiuapwnlswv3RgM-riyZD87o0,6
10
+ isrpa-0.6.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- isrpa/__init__.py,sha256=pG-YPVG0gJIJ6s4xcAz9S_CnUxpUcz33wl9eNUSgxGk,20
2
- isrpa/utils.py,sha256=dT6DQtckt2eOwACv6-j3T0mRfBMAtvraGBC0M8KqB6g,50827
3
- isrpa-0.5.dist-info/METADATA,sha256=BVtalx7nJupCnm7a1-YYP7qTpS-6XO1Ve4pr5gr-CkU,457
4
- isrpa-0.5.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
5
- isrpa-0.5.dist-info/top_level.txt,sha256=J5HJbtR2WAeKnW1rrpkiuapwnlswv3RgM-riyZD87o0,6
6
- isrpa-0.5.dist-info/RECORD,,
File without changes