pyxllib 0.3.197__py3-none-any.whl → 3.201.1__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.
Files changed (127) hide show
  1. pyxllib/__init__.py +14 -21
  2. pyxllib/algo/__init__.py +8 -8
  3. pyxllib/algo/disjoint.py +54 -54
  4. pyxllib/algo/geo.py +537 -541
  5. pyxllib/algo/intervals.py +964 -964
  6. pyxllib/algo/matcher.py +389 -389
  7. pyxllib/algo/newbie.py +166 -166
  8. pyxllib/algo/pupil.py +629 -629
  9. pyxllib/algo/shapelylib.py +67 -67
  10. pyxllib/algo/specialist.py +241 -241
  11. pyxllib/algo/stat.py +494 -494
  12. pyxllib/algo/treelib.py +145 -149
  13. pyxllib/algo/unitlib.py +62 -66
  14. pyxllib/autogui/__init__.py +5 -5
  15. pyxllib/autogui/activewin.py +246 -246
  16. pyxllib/autogui/all.py +9 -9
  17. pyxllib/autogui/autogui.py +846 -852
  18. pyxllib/autogui/uiautolib.py +362 -362
  19. pyxllib/autogui/virtualkey.py +102 -102
  20. pyxllib/autogui/wechat.py +827 -827
  21. pyxllib/autogui/wechat_msg.py +421 -421
  22. pyxllib/autogui/wxautolib.py +84 -84
  23. pyxllib/cv/__init__.py +5 -5
  24. pyxllib/cv/expert.py +267 -267
  25. pyxllib/cv/imfile.py +159 -159
  26. pyxllib/cv/imhash.py +39 -39
  27. pyxllib/cv/pupil.py +9 -9
  28. pyxllib/cv/rgbfmt.py +1525 -1525
  29. pyxllib/cv/slidercaptcha.py +137 -137
  30. pyxllib/cv/trackbartools.py +251 -251
  31. pyxllib/cv/xlcvlib.py +1040 -1040
  32. pyxllib/cv/xlpillib.py +423 -423
  33. pyxllib/data/echarts.py +236 -240
  34. pyxllib/data/jsonlib.py +85 -89
  35. pyxllib/data/oss.py +72 -72
  36. pyxllib/data/pglib.py +1111 -1127
  37. pyxllib/data/sqlite.py +568 -568
  38. pyxllib/data/sqllib.py +297 -297
  39. pyxllib/ext/JLineViewer.py +505 -505
  40. pyxllib/ext/__init__.py +6 -6
  41. pyxllib/ext/demolib.py +251 -246
  42. pyxllib/ext/drissionlib.py +277 -277
  43. pyxllib/ext/kq5034lib.py +12 -12
  44. pyxllib/ext/qt.py +449 -449
  45. pyxllib/ext/robustprocfile.py +493 -497
  46. pyxllib/ext/seleniumlib.py +76 -76
  47. pyxllib/ext/tk.py +173 -173
  48. pyxllib/ext/unixlib.py +821 -827
  49. pyxllib/ext/utools.py +345 -351
  50. pyxllib/ext/webhook.py +124 -119
  51. pyxllib/ext/win32lib.py +40 -40
  52. pyxllib/ext/wjxlib.py +91 -88
  53. pyxllib/ext/wpsapi.py +124 -124
  54. pyxllib/ext/xlwork.py +9 -9
  55. pyxllib/ext/yuquelib.py +1110 -1105
  56. pyxllib/file/__init__.py +17 -17
  57. pyxllib/file/docxlib.py +757 -761
  58. pyxllib/file/gitlib.py +309 -309
  59. pyxllib/file/libreoffice.py +165 -165
  60. pyxllib/file/movielib.py +144 -148
  61. pyxllib/file/newbie.py +10 -10
  62. pyxllib/file/onenotelib.py +1469 -1469
  63. pyxllib/file/packlib/__init__.py +330 -330
  64. pyxllib/file/packlib/zipfile.py +2441 -2441
  65. pyxllib/file/pdflib.py +422 -426
  66. pyxllib/file/pupil.py +185 -185
  67. pyxllib/file/specialist/__init__.py +681 -685
  68. pyxllib/file/specialist/dirlib.py +799 -799
  69. pyxllib/file/specialist/download.py +193 -193
  70. pyxllib/file/specialist/filelib.py +2825 -2829
  71. pyxllib/file/xlsxlib.py +3122 -3131
  72. pyxllib/file/xlsyncfile.py +341 -341
  73. pyxllib/prog/__init__.py +5 -5
  74. pyxllib/prog/cachetools.py +58 -64
  75. pyxllib/prog/deprecatedlib.py +233 -233
  76. pyxllib/prog/filelock.py +42 -42
  77. pyxllib/prog/ipyexec.py +253 -253
  78. pyxllib/prog/multiprogs.py +940 -940
  79. pyxllib/prog/newbie.py +451 -451
  80. pyxllib/prog/pupil.py +1208 -1197
  81. pyxllib/prog/sitepackages.py +33 -33
  82. pyxllib/prog/specialist/__init__.py +348 -391
  83. pyxllib/prog/specialist/bc.py +203 -203
  84. pyxllib/prog/specialist/browser.py +497 -497
  85. pyxllib/prog/specialist/common.py +347 -347
  86. pyxllib/prog/specialist/datetime.py +198 -198
  87. pyxllib/prog/specialist/tictoc.py +240 -240
  88. pyxllib/prog/specialist/xllog.py +180 -180
  89. pyxllib/prog/xlosenv.py +110 -108
  90. pyxllib/stdlib/__init__.py +17 -17
  91. pyxllib/stdlib/tablepyxl/__init__.py +10 -10
  92. pyxllib/stdlib/tablepyxl/style.py +303 -303
  93. pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
  94. pyxllib/text/__init__.py +8 -8
  95. pyxllib/text/ahocorasick.py +36 -39
  96. pyxllib/text/airscript.js +754 -744
  97. pyxllib/text/charclasslib.py +121 -121
  98. pyxllib/text/jiebalib.py +267 -267
  99. pyxllib/text/jinjalib.py +27 -32
  100. pyxllib/text/jsa_ai_prompt.md +271 -271
  101. pyxllib/text/jscode.py +922 -922
  102. pyxllib/text/latex/__init__.py +158 -158
  103. pyxllib/text/levenshtein.py +303 -303
  104. pyxllib/text/nestenv.py +1215 -1215
  105. pyxllib/text/newbie.py +300 -300
  106. pyxllib/text/pupil/__init__.py +8 -8
  107. pyxllib/text/pupil/common.py +1121 -1121
  108. pyxllib/text/pupil/xlalign.py +326 -326
  109. pyxllib/text/pycode.py +47 -47
  110. pyxllib/text/specialist/__init__.py +8 -8
  111. pyxllib/text/specialist/common.py +112 -112
  112. pyxllib/text/specialist/ptag.py +186 -186
  113. pyxllib/text/spellchecker.py +172 -172
  114. pyxllib/text/templates/echart_base.html +10 -10
  115. pyxllib/text/templates/highlight_code.html +16 -16
  116. pyxllib/text/templates/latex_editor.html +102 -102
  117. pyxllib/text/vbacode.py +17 -17
  118. pyxllib/text/xmllib.py +741 -747
  119. pyxllib/xl.py +42 -39
  120. pyxllib/xlcv.py +17 -17
  121. pyxllib-3.201.1.dist-info/METADATA +296 -0
  122. pyxllib-3.201.1.dist-info/RECORD +125 -0
  123. {pyxllib-0.3.197.dist-info → pyxllib-3.201.1.dist-info}/licenses/LICENSE +190 -190
  124. pyxllib/ext/old.py +0 -663
  125. pyxllib-0.3.197.dist-info/METADATA +0 -48
  126. pyxllib-0.3.197.dist-info/RECORD +0 -126
  127. {pyxllib-0.3.197.dist-info → pyxllib-3.201.1.dist-info}/WHEEL +0 -0
@@ -1,137 +1,137 @@
1
- import os
2
- import cv2
3
- import numpy as np
4
- from xlproject.code4101 import XlPath
5
-
6
- from pyxllib.file.specialist import download_file
7
- from pyxllib.prog.pupil import is_url
8
-
9
-
10
- class SliderCaptchaLocator:
11
- """ 滑动验证码的位置定位
12
-
13
- 由于缺口一般是一个黑底图,整体颜色是偏暗的,可以利用这个特性来定位列所在位置
14
- """
15
-
16
- def __init__(self, background_image_path, slider_image_path=None):
17
- """
18
- :param background_image_path: 背景主图片
19
- :param slider_image_path: 滑动条图片
20
- """
21
- # 支持输入是url的情况
22
- if is_url(background_image_path):
23
- background_image_path = download_file(background_image_path, temp=True, ext='.png')
24
- if is_url(slider_image_path):
25
- slider_image_path = download_file(slider_image_path, temp=True, ext='.png')
26
- # 初始化图片等数据
27
- self.image_path = background_image_path
28
- self.image = cv2.imread(self.image_path)
29
- self.darkest_rows = None
30
- self.column_averages = None
31
- self.enhanced_averages = None
32
- self.radius = 24
33
- if slider_image_path is not None:
34
- # 先读取图片
35
- template_image = cv2.imread(slider_image_path)
36
- # 取图片宽度的40%作为radius
37
- self.radius = int(template_image.shape[1] * 0.4)
38
-
39
- def select_darkest_part_rows(self, fraction=0.1):
40
- """
41
- 选择最暗的部分行,供下游计算列的平均暗度
42
-
43
- :param float fraction: 最暗行的比例
44
- :return: 最暗行的图像部分
45
- """
46
- if self.darkest_rows is None:
47
- average_row_values = np.mean(self.image, axis=(1, 2))
48
- threshold_index = int(len(average_row_values) * fraction)
49
- darkest_indices = np.argsort(average_row_values)[:threshold_index]
50
- self.darkest_rows = self.image[darkest_indices]
51
- return self.darkest_rows
52
-
53
- def calculate_column_averages(self):
54
- """
55
- 计算列的平均强度。
56
-
57
- :return: 列的平均强度
58
- """
59
- if self.column_averages is None:
60
- rows = self.select_darkest_part_rows()
61
- column_values = np.mean(rows, axis=0)
62
- column_intensity = np.mean(column_values, axis=1)
63
- min_val, max_val = np.min(column_intensity), np.max(column_intensity)
64
- self.column_averages = ((column_intensity - min_val) / (max_val - min_val) * 255).astype(
65
- np.uint8) if max_val != min_val else np.zeros_like(column_intensity)
66
- return self.column_averages
67
-
68
- def enhance_column_averages(self):
69
- """
70
- 增强列平均值,利用验证码的黑度图的对称性,进行一个增强,使得其他非验证码的零散黑条变白
71
-
72
- :param int radius: 对比半径,这个建议设成模版图宽度的40%~50%
73
- :return: 增强后的列平均值
74
- """
75
- if self.enhanced_averages is None:
76
- averages = self.calculate_column_averages()
77
- length = len(averages)
78
- enhanced = np.zeros_like(averages)
79
- for i in range(length):
80
- max_value = averages[i]
81
- for j in range(1, self.radius // 2 + 1):
82
- if i - j >= 0 and i + j < length:
83
- max_value = max(max_value, abs(int(averages[i - j]) - int(averages[i + j])))
84
- enhanced[i] = max_value
85
- self.enhanced_averages = enhanced
86
- return self.enhanced_averages
87
-
88
- def find_captcha_position(self, threshold=50):
89
- """
90
- 查找验证码的位置。
91
-
92
- :param int threshold: 达到多少像素后,开始计算中位数
93
- :return: 验证码的列中心位置
94
- """
95
- intensities = self.enhance_column_averages()
96
- indices = []
97
- for intensity in range(256):
98
- new_indices = np.where(intensities == intensity)[0]
99
- if len(indices) + len(new_indices) > threshold:
100
- indices.extend(new_indices[:threshold - len(indices)])
101
- break
102
- indices.extend(new_indices)
103
- return int(np.median(indices))
104
-
105
- def draw_red_line(self, position, line_thickness=3):
106
- """
107
- 在图像上绘制红线。
108
-
109
- :param int position: 红线位置
110
- :param int line_thickness: 线宽
111
- :return: 绘制红线后的图像
112
- """
113
- gray_image = np.tile(self.calculate_column_averages(), (100, 1)).astype(np.uint8)
114
- color_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
115
- cv2.line(color_image, (position, 0), (position, gray_image.shape[0]), (0, 0, 255), line_thickness)
116
- return color_image
117
-
118
- def debug(self):
119
- position = self.find_captcha_position()
120
- final_image = self.draw_red_line(position)
121
- cv2.imshow('Image with Red Line', final_image)
122
- cv2.waitKey(0)
123
- cv2.destroyAllWindows()
124
-
125
-
126
- def main():
127
- os.chdir(XlPath.desktop())
128
- locator = SliderCaptchaLocator('cap_union_new_getcapbysig.png')
129
- position = locator.find_captcha_position()
130
- final_image = locator.draw_red_line(position)
131
- cv2.imshow('Image with Red Line', final_image)
132
- cv2.waitKey(0)
133
- cv2.destroyAllWindows()
134
-
135
-
136
- if __name__ == '__main__':
137
- main()
1
+ import os
2
+ import cv2
3
+ import numpy as np
4
+ from xlproject.code4101 import XlPath
5
+
6
+ from pyxllib.file.specialist import download_file
7
+ from pyxllib.prog.pupil import is_url
8
+
9
+
10
+ class SliderCaptchaLocator:
11
+ """ 滑动验证码的位置定位
12
+
13
+ 由于缺口一般是一个黑底图,整体颜色是偏暗的,可以利用这个特性来定位列所在位置
14
+ """
15
+
16
+ def __init__(self, background_image_path, slider_image_path=None):
17
+ """
18
+ :param background_image_path: 背景主图片
19
+ :param slider_image_path: 滑动条图片
20
+ """
21
+ # 支持输入是url的情况
22
+ if is_url(background_image_path):
23
+ background_image_path = download_file(background_image_path, temp=True, ext='.png')
24
+ if is_url(slider_image_path):
25
+ slider_image_path = download_file(slider_image_path, temp=True, ext='.png')
26
+ # 初始化图片等数据
27
+ self.image_path = background_image_path
28
+ self.image = cv2.imread(self.image_path)
29
+ self.darkest_rows = None
30
+ self.column_averages = None
31
+ self.enhanced_averages = None
32
+ self.radius = 24
33
+ if slider_image_path is not None:
34
+ # 先读取图片
35
+ template_image = cv2.imread(slider_image_path)
36
+ # 取图片宽度的40%作为radius
37
+ self.radius = int(template_image.shape[1] * 0.4)
38
+
39
+ def select_darkest_part_rows(self, fraction=0.1):
40
+ """
41
+ 选择最暗的部分行,供下游计算列的平均暗度
42
+
43
+ :param float fraction: 最暗行的比例
44
+ :return: 最暗行的图像部分
45
+ """
46
+ if self.darkest_rows is None:
47
+ average_row_values = np.mean(self.image, axis=(1, 2))
48
+ threshold_index = int(len(average_row_values) * fraction)
49
+ darkest_indices = np.argsort(average_row_values)[:threshold_index]
50
+ self.darkest_rows = self.image[darkest_indices]
51
+ return self.darkest_rows
52
+
53
+ def calculate_column_averages(self):
54
+ """
55
+ 计算列的平均强度。
56
+
57
+ :return: 列的平均强度
58
+ """
59
+ if self.column_averages is None:
60
+ rows = self.select_darkest_part_rows()
61
+ column_values = np.mean(rows, axis=0)
62
+ column_intensity = np.mean(column_values, axis=1)
63
+ min_val, max_val = np.min(column_intensity), np.max(column_intensity)
64
+ self.column_averages = ((column_intensity - min_val) / (max_val - min_val) * 255).astype(
65
+ np.uint8) if max_val != min_val else np.zeros_like(column_intensity)
66
+ return self.column_averages
67
+
68
+ def enhance_column_averages(self):
69
+ """
70
+ 增强列平均值,利用验证码的黑度图的对称性,进行一个增强,使得其他非验证码的零散黑条变白
71
+
72
+ :param int radius: 对比半径,这个建议设成模版图宽度的40%~50%
73
+ :return: 增强后的列平均值
74
+ """
75
+ if self.enhanced_averages is None:
76
+ averages = self.calculate_column_averages()
77
+ length = len(averages)
78
+ enhanced = np.zeros_like(averages)
79
+ for i in range(length):
80
+ max_value = averages[i]
81
+ for j in range(1, self.radius // 2 + 1):
82
+ if i - j >= 0 and i + j < length:
83
+ max_value = max(max_value, abs(int(averages[i - j]) - int(averages[i + j])))
84
+ enhanced[i] = max_value
85
+ self.enhanced_averages = enhanced
86
+ return self.enhanced_averages
87
+
88
+ def find_captcha_position(self, threshold=50):
89
+ """
90
+ 查找验证码的位置。
91
+
92
+ :param int threshold: 达到多少像素后,开始计算中位数
93
+ :return: 验证码的列中心位置
94
+ """
95
+ intensities = self.enhance_column_averages()
96
+ indices = []
97
+ for intensity in range(256):
98
+ new_indices = np.where(intensities == intensity)[0]
99
+ if len(indices) + len(new_indices) > threshold:
100
+ indices.extend(new_indices[:threshold - len(indices)])
101
+ break
102
+ indices.extend(new_indices)
103
+ return int(np.median(indices))
104
+
105
+ def draw_red_line(self, position, line_thickness=3):
106
+ """
107
+ 在图像上绘制红线。
108
+
109
+ :param int position: 红线位置
110
+ :param int line_thickness: 线宽
111
+ :return: 绘制红线后的图像
112
+ """
113
+ gray_image = np.tile(self.calculate_column_averages(), (100, 1)).astype(np.uint8)
114
+ color_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2BGR)
115
+ cv2.line(color_image, (position, 0), (position, gray_image.shape[0]), (0, 0, 255), line_thickness)
116
+ return color_image
117
+
118
+ def debug(self):
119
+ position = self.find_captcha_position()
120
+ final_image = self.draw_red_line(position)
121
+ cv2.imshow('Image with Red Line', final_image)
122
+ cv2.waitKey(0)
123
+ cv2.destroyAllWindows()
124
+
125
+
126
+ def main():
127
+ os.chdir(XlPath.desktop())
128
+ locator = SliderCaptchaLocator('cap_union_new_getcapbysig.png')
129
+ position = locator.find_captcha_position()
130
+ final_image = locator.draw_red_line(position)
131
+ cv2.imshow('Image with Red Line', final_image)
132
+ cv2.waitKey(0)
133
+ cv2.destroyAllWindows()
134
+
135
+
136
+ if __name__ == '__main__':
137
+ main()