pyxllib 0.3.197__py3-none-any.whl → 0.3.200__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.
- pyxllib/__init__.py +21 -21
- pyxllib/algo/__init__.py +8 -8
- pyxllib/algo/disjoint.py +54 -54
- pyxllib/algo/geo.py +541 -541
- pyxllib/algo/intervals.py +964 -964
- pyxllib/algo/matcher.py +389 -389
- pyxllib/algo/newbie.py +166 -166
- pyxllib/algo/pupil.py +629 -629
- pyxllib/algo/shapelylib.py +67 -67
- pyxllib/algo/specialist.py +241 -241
- pyxllib/algo/stat.py +494 -494
- pyxllib/algo/treelib.py +149 -149
- pyxllib/algo/unitlib.py +66 -66
- pyxllib/autogui/__init__.py +5 -5
- pyxllib/autogui/activewin.py +246 -246
- pyxllib/autogui/all.py +9 -9
- pyxllib/autogui/autogui.py +852 -852
- pyxllib/autogui/uiautolib.py +362 -362
- pyxllib/autogui/virtualkey.py +102 -102
- pyxllib/autogui/wechat.py +827 -827
- pyxllib/autogui/wechat_msg.py +421 -421
- pyxllib/autogui/wxautolib.py +84 -84
- pyxllib/cv/__init__.py +5 -5
- pyxllib/cv/expert.py +267 -267
- pyxllib/cv/imfile.py +159 -159
- pyxllib/cv/imhash.py +39 -39
- pyxllib/cv/pupil.py +9 -9
- pyxllib/cv/rgbfmt.py +1525 -1525
- pyxllib/cv/slidercaptcha.py +137 -137
- pyxllib/cv/trackbartools.py +251 -251
- pyxllib/cv/xlcvlib.py +1040 -1040
- pyxllib/cv/xlpillib.py +423 -423
- pyxllib/data/echarts.py +240 -240
- pyxllib/data/jsonlib.py +89 -89
- pyxllib/data/oss.py +72 -72
- pyxllib/data/pglib.py +1127 -1127
- pyxllib/data/sqlite.py +568 -568
- pyxllib/data/sqllib.py +297 -297
- pyxllib/ext/JLineViewer.py +505 -505
- pyxllib/ext/__init__.py +6 -6
- pyxllib/ext/demolib.py +246 -246
- pyxllib/ext/drissionlib.py +277 -277
- pyxllib/ext/kq5034lib.py +12 -12
- pyxllib/ext/old.py +663 -663
- pyxllib/ext/qt.py +449 -449
- pyxllib/ext/robustprocfile.py +497 -497
- pyxllib/ext/seleniumlib.py +76 -76
- pyxllib/ext/tk.py +173 -173
- pyxllib/ext/unixlib.py +827 -827
- pyxllib/ext/utools.py +351 -351
- pyxllib/ext/webhook.py +124 -119
- pyxllib/ext/win32lib.py +40 -40
- pyxllib/ext/wjxlib.py +88 -88
- pyxllib/ext/wpsapi.py +124 -124
- pyxllib/ext/xlwork.py +9 -9
- pyxllib/ext/yuquelib.py +1105 -1105
- pyxllib/file/__init__.py +17 -17
- pyxllib/file/docxlib.py +761 -761
- pyxllib/file/gitlib.py +309 -309
- pyxllib/file/libreoffice.py +165 -165
- pyxllib/file/movielib.py +148 -148
- pyxllib/file/newbie.py +10 -10
- pyxllib/file/onenotelib.py +1469 -1469
- pyxllib/file/packlib/__init__.py +330 -330
- pyxllib/file/packlib/zipfile.py +2441 -2441
- pyxllib/file/pdflib.py +426 -426
- pyxllib/file/pupil.py +185 -185
- pyxllib/file/specialist/__init__.py +685 -685
- pyxllib/file/specialist/dirlib.py +799 -799
- pyxllib/file/specialist/download.py +193 -193
- pyxllib/file/specialist/filelib.py +2829 -2829
- pyxllib/file/xlsxlib.py +3131 -3131
- pyxllib/file/xlsyncfile.py +341 -341
- pyxllib/prog/__init__.py +5 -5
- pyxllib/prog/cachetools.py +64 -64
- pyxllib/prog/deprecatedlib.py +233 -233
- pyxllib/prog/filelock.py +42 -42
- pyxllib/prog/ipyexec.py +253 -253
- pyxllib/prog/multiprogs.py +940 -940
- pyxllib/prog/newbie.py +451 -451
- pyxllib/prog/pupil.py +1197 -1197
- pyxllib/prog/sitepackages.py +33 -33
- pyxllib/prog/specialist/__init__.py +391 -391
- pyxllib/prog/specialist/bc.py +203 -203
- pyxllib/prog/specialist/browser.py +497 -497
- pyxllib/prog/specialist/common.py +347 -347
- pyxllib/prog/specialist/datetime.py +198 -198
- pyxllib/prog/specialist/tictoc.py +240 -240
- pyxllib/prog/specialist/xllog.py +180 -180
- pyxllib/prog/xlosenv.py +108 -108
- pyxllib/stdlib/__init__.py +17 -17
- pyxllib/stdlib/tablepyxl/__init__.py +10 -10
- pyxllib/stdlib/tablepyxl/style.py +303 -303
- pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
- pyxllib/text/__init__.py +8 -8
- pyxllib/text/ahocorasick.py +39 -39
- pyxllib/text/airscript.js +744 -744
- pyxllib/text/charclasslib.py +121 -121
- pyxllib/text/jiebalib.py +267 -267
- pyxllib/text/jinjalib.py +32 -32
- pyxllib/text/jsa_ai_prompt.md +271 -271
- pyxllib/text/jscode.py +922 -922
- pyxllib/text/latex/__init__.py +158 -158
- pyxllib/text/levenshtein.py +303 -303
- pyxllib/text/nestenv.py +1215 -1215
- pyxllib/text/newbie.py +300 -300
- pyxllib/text/pupil/__init__.py +8 -8
- pyxllib/text/pupil/common.py +1121 -1121
- pyxllib/text/pupil/xlalign.py +326 -326
- pyxllib/text/pycode.py +47 -47
- pyxllib/text/specialist/__init__.py +8 -8
- pyxllib/text/specialist/common.py +112 -112
- pyxllib/text/specialist/ptag.py +186 -186
- pyxllib/text/spellchecker.py +172 -172
- pyxllib/text/templates/echart_base.html +10 -10
- pyxllib/text/templates/highlight_code.html +16 -16
- pyxllib/text/templates/latex_editor.html +102 -102
- pyxllib/text/vbacode.py +17 -17
- pyxllib/text/xmllib.py +747 -747
- pyxllib/xl.py +42 -39
- pyxllib/xlcv.py +17 -17
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/METADATA +1 -1
- pyxllib-0.3.200.dist-info/RECORD +126 -0
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/licenses/LICENSE +190 -190
- pyxllib-0.3.197.dist-info/RECORD +0 -126
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/WHEEL +0 -0
pyxllib/ext/wpsapi.py
CHANGED
@@ -1,124 +1,124 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# @Author : 陈坤泽
|
4
|
-
# @Date : 2024/07/31
|
5
|
-
|
6
|
-
import os
|
7
|
-
import re
|
8
|
-
|
9
|
-
import requests
|
10
|
-
import pandas as pd
|
11
|
-
|
12
|
-
|
13
|
-
class WpsOnlineBook:
|
14
|
-
""" wps的"脚本令牌"调用模式
|
15
|
-
|
16
|
-
官方文档:https://airsheet.wps.cn/docs/apitoken/api.html
|
17
|
-
"""
|
18
|
-
|
19
|
-
def __1_基础功能(self):
|
20
|
-
pass
|
21
|
-
|
22
|
-
def __init__(self, file_id, script_id=None, *, token=None):
|
23
|
-
self.headers = {
|
24
|
-
'Content-Type': "application/json",
|
25
|
-
'AirScript-Token': token or os.getenv('WPS_SCRIPT_TOKEN', ''),
|
26
|
-
}
|
27
|
-
self.file_id = file_id
|
28
|
-
self.default_script_id = script_id
|
29
|
-
|
30
|
-
def post_request(self, url, payload):
|
31
|
-
"""
|
32
|
-
发送 POST 请求到指定的 URL 并返回响应结果
|
33
|
-
"""
|
34
|
-
try:
|
35
|
-
resp = requests.post(url, json=payload, headers=self.headers)
|
36
|
-
resp.raise_for_status() # 如果请求失败会抛出异常
|
37
|
-
return resp.json()
|
38
|
-
except requests.exceptions.RequestException as e:
|
39
|
-
print(f"请求失败: {e}")
|
40
|
-
return None
|
41
|
-
|
42
|
-
def run_script(self, script_id=None, context_argv=None, sync=True):
|
43
|
-
""" 原本执行 WPS 脚本并返回执行结果
|
44
|
-
|
45
|
-
:param script_id: 脚本 ID
|
46
|
-
:param context_argv: 脚本参数 (可选)
|
47
|
-
context本来能支持这些参数的:
|
48
|
-
dict argv: 传入的上下文参数对象,比如传入{name: 'xiaomeng', age: 18}, 在 AS 代码中可通过Context.argv.name获取到传入的值
|
49
|
-
str sheet_name: et,ksheet 运行时所在表名
|
50
|
-
str range: et,ksheet 运行时所在区域,例如$B$156
|
51
|
-
str link_from: et,ksheet 点击超链接所在单元格
|
52
|
-
str db_active_view: db 运行时所在 view 名
|
53
|
-
str db_selection: db 运行时所在选区
|
54
|
-
但是,sheet_name, range等,并看不到对运行代码有什么实质影响,不影响active,而且as里也引用不了sheet_name等值
|
55
|
-
所以退化,简化为只要传入content_argv参数就行
|
56
|
-
:param sync:
|
57
|
-
True, 同步运行
|
58
|
-
False, 异步运行
|
59
|
-
|
60
|
-
这个接口跟普通as一样,运行有30秒时限
|
61
|
-
"""
|
62
|
-
url = f"https://www.kdocs.cn/api/v3/ide/file/{self.file_id}/script/{script_id}/{'sync_task' if sync else 'task'}"
|
63
|
-
payload = {
|
64
|
-
"Context": {'argv': context_argv or {}}
|
65
|
-
}
|
66
|
-
res = self.post_request(url, payload)
|
67
|
-
if sync:
|
68
|
-
return res['data']['result']
|
69
|
-
else:
|
70
|
-
return res
|
71
|
-
|
72
|
-
def __2_封装的更高级的接口(self):
|
73
|
-
""" 这系列的功能需要配套这个框架范式使用:
|
74
|
-
https://github.com/XLPRUtils/pyxllib/blob/master/pyxllib/text/airscript.js
|
75
|
-
"""
|
76
|
-
pass
|
77
|
-
|
78
|
-
def run_func(self, func_name, *args):
|
79
|
-
""" 我自己常用的jsa框架,jsa那边已经简化了对接模式,所以一般都只用这个高级的接口即可
|
80
|
-
(旧函数名run_script2不再使用)
|
81
|
-
"""
|
82
|
-
return self.run_script(self.default_script_id, context_argv={'funcName': func_name, 'args': args})
|
83
|
-
|
84
|
-
def get_sheet_data(self, sheet_name, fields, data_row=0, filter_empty_rows=True, *,
|
85
|
-
return_mode='pd') -> pd.DataFrame:
|
86
|
-
""" 获取某张sheet表格数据
|
87
|
-
|
88
|
-
:param sheet_name: sheet表名
|
89
|
-
:param list[str] fields: 字段名列表
|
90
|
-
:param int data_row: 数据起始行,详细用法见packTableDataFields
|
91
|
-
:param return_mode: 'pd' or 'json'
|
92
|
-
"""
|
93
|
-
data = self.run_func('packTableDataFields', sheet_name, fields, data_row, filter_empty_rows)
|
94
|
-
if return_mode == 'json':
|
95
|
-
return data
|
96
|
-
elif return_mode == 'pd':
|
97
|
-
return pd.DataFrame(data)
|
98
|
-
|
99
|
-
def write_arr(self, rows, start_cell, batch_size=None):
|
100
|
-
""" 把一个二维数组数据写入表格
|
101
|
-
|
102
|
-
:param rows: 一个n*m的数据
|
103
|
-
:param start_cell: 写入的起始位置,例如'A1',也可以使用Sheet1!A1的格式表示具体的表格位置
|
104
|
-
:param batch_size: 为了避免一次写入内容过多,超时写入失败,可以分成多批运行
|
105
|
-
这里写每批的数据行数
|
106
|
-
默认表示一次性全部提交
|
107
|
-
:return:
|
108
|
-
"""
|
109
|
-
if batch_size is None:
|
110
|
-
batch_size = len(rows) # 如果未指定批次大小,一次性写入所有行
|
111
|
-
|
112
|
-
def func(m):
|
113
|
-
return str(int(m.group()) + batch_size)
|
114
|
-
|
115
|
-
current_cell = start_cell
|
116
|
-
for start in range(0, len(rows), batch_size):
|
117
|
-
end = start + batch_size
|
118
|
-
batch_rows = rows[start:end]
|
119
|
-
self.run_func('writeArrToSheet', batch_rows, current_cell)
|
120
|
-
current_cell = re.sub(r'\d+$', func, current_cell)
|
121
|
-
|
122
|
-
|
123
|
-
if __name__ == '__main__':
|
124
|
-
pass
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Date : 2024/07/31
|
5
|
+
|
6
|
+
import os
|
7
|
+
import re
|
8
|
+
|
9
|
+
import requests
|
10
|
+
import pandas as pd
|
11
|
+
|
12
|
+
|
13
|
+
class WpsOnlineBook:
|
14
|
+
""" wps的"脚本令牌"调用模式
|
15
|
+
|
16
|
+
官方文档:https://airsheet.wps.cn/docs/apitoken/api.html
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __1_基础功能(self):
|
20
|
+
pass
|
21
|
+
|
22
|
+
def __init__(self, file_id, script_id=None, *, token=None):
|
23
|
+
self.headers = {
|
24
|
+
'Content-Type': "application/json",
|
25
|
+
'AirScript-Token': token or os.getenv('WPS_SCRIPT_TOKEN', ''),
|
26
|
+
}
|
27
|
+
self.file_id = file_id
|
28
|
+
self.default_script_id = script_id
|
29
|
+
|
30
|
+
def post_request(self, url, payload):
|
31
|
+
"""
|
32
|
+
发送 POST 请求到指定的 URL 并返回响应结果
|
33
|
+
"""
|
34
|
+
try:
|
35
|
+
resp = requests.post(url, json=payload, headers=self.headers)
|
36
|
+
resp.raise_for_status() # 如果请求失败会抛出异常
|
37
|
+
return resp.json()
|
38
|
+
except requests.exceptions.RequestException as e:
|
39
|
+
print(f"请求失败: {e}")
|
40
|
+
return None
|
41
|
+
|
42
|
+
def run_script(self, script_id=None, context_argv=None, sync=True):
|
43
|
+
""" 原本执行 WPS 脚本并返回执行结果
|
44
|
+
|
45
|
+
:param script_id: 脚本 ID
|
46
|
+
:param context_argv: 脚本参数 (可选)
|
47
|
+
context本来能支持这些参数的:
|
48
|
+
dict argv: 传入的上下文参数对象,比如传入{name: 'xiaomeng', age: 18}, 在 AS 代码中可通过Context.argv.name获取到传入的值
|
49
|
+
str sheet_name: et,ksheet 运行时所在表名
|
50
|
+
str range: et,ksheet 运行时所在区域,例如$B$156
|
51
|
+
str link_from: et,ksheet 点击超链接所在单元格
|
52
|
+
str db_active_view: db 运行时所在 view 名
|
53
|
+
str db_selection: db 运行时所在选区
|
54
|
+
但是,sheet_name, range等,并看不到对运行代码有什么实质影响,不影响active,而且as里也引用不了sheet_name等值
|
55
|
+
所以退化,简化为只要传入content_argv参数就行
|
56
|
+
:param sync:
|
57
|
+
True, 同步运行
|
58
|
+
False, 异步运行
|
59
|
+
|
60
|
+
这个接口跟普通as一样,运行有30秒时限
|
61
|
+
"""
|
62
|
+
url = f"https://www.kdocs.cn/api/v3/ide/file/{self.file_id}/script/{script_id}/{'sync_task' if sync else 'task'}"
|
63
|
+
payload = {
|
64
|
+
"Context": {'argv': context_argv or {}}
|
65
|
+
}
|
66
|
+
res = self.post_request(url, payload)
|
67
|
+
if sync:
|
68
|
+
return res['data']['result']
|
69
|
+
else:
|
70
|
+
return res
|
71
|
+
|
72
|
+
def __2_封装的更高级的接口(self):
|
73
|
+
""" 这系列的功能需要配套这个框架范式使用:
|
74
|
+
https://github.com/XLPRUtils/pyxllib/blob/master/pyxllib/text/airscript.js
|
75
|
+
"""
|
76
|
+
pass
|
77
|
+
|
78
|
+
def run_func(self, func_name, *args):
|
79
|
+
""" 我自己常用的jsa框架,jsa那边已经简化了对接模式,所以一般都只用这个高级的接口即可
|
80
|
+
(旧函数名run_script2不再使用)
|
81
|
+
"""
|
82
|
+
return self.run_script(self.default_script_id, context_argv={'funcName': func_name, 'args': args})
|
83
|
+
|
84
|
+
def get_sheet_data(self, sheet_name, fields, data_row=0, filter_empty_rows=True, *,
|
85
|
+
return_mode='pd') -> pd.DataFrame:
|
86
|
+
""" 获取某张sheet表格数据
|
87
|
+
|
88
|
+
:param sheet_name: sheet表名
|
89
|
+
:param list[str] fields: 字段名列表
|
90
|
+
:param int data_row: 数据起始行,详细用法见packTableDataFields
|
91
|
+
:param return_mode: 'pd' or 'json'
|
92
|
+
"""
|
93
|
+
data = self.run_func('packTableDataFields', sheet_name, fields, data_row, filter_empty_rows)
|
94
|
+
if return_mode == 'json':
|
95
|
+
return data
|
96
|
+
elif return_mode == 'pd':
|
97
|
+
return pd.DataFrame(data)
|
98
|
+
|
99
|
+
def write_arr(self, rows, start_cell, batch_size=None):
|
100
|
+
""" 把一个二维数组数据写入表格
|
101
|
+
|
102
|
+
:param rows: 一个n*m的数据
|
103
|
+
:param start_cell: 写入的起始位置,例如'A1',也可以使用Sheet1!A1的格式表示具体的表格位置
|
104
|
+
:param batch_size: 为了避免一次写入内容过多,超时写入失败,可以分成多批运行
|
105
|
+
这里写每批的数据行数
|
106
|
+
默认表示一次性全部提交
|
107
|
+
:return:
|
108
|
+
"""
|
109
|
+
if batch_size is None:
|
110
|
+
batch_size = len(rows) # 如果未指定批次大小,一次性写入所有行
|
111
|
+
|
112
|
+
def func(m):
|
113
|
+
return str(int(m.group()) + batch_size)
|
114
|
+
|
115
|
+
current_cell = start_cell
|
116
|
+
for start in range(0, len(rows), batch_size):
|
117
|
+
end = start + batch_size
|
118
|
+
batch_rows = rows[start:end]
|
119
|
+
self.run_func('writeArrToSheet', batch_rows, current_cell)
|
120
|
+
current_cell = re.sub(r'\d+$', func, current_cell)
|
121
|
+
|
122
|
+
|
123
|
+
if __name__ == '__main__':
|
124
|
+
pass
|
pyxllib/ext/xlwork.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# @Author : 陈坤泽
|
4
|
-
# @Email : 877362867@qq.com
|
5
|
-
# @Date : 2025/04/17
|
6
|
-
|
7
|
-
""" code4101的众多账号密码管理接口,工作目录等控制位置 """
|
8
|
-
|
9
|
-
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Email : 877362867@qq.com
|
5
|
+
# @Date : 2025/04/17
|
6
|
+
|
7
|
+
""" code4101的众多账号密码管理接口,工作目录等控制位置 """
|
8
|
+
|
9
|
+
|