qrpa 1.0.24__py3-none-any.whl → 1.0.25__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 qrpa might be problematic. Click here for more details.
- qrpa/__init__.py +2 -1
- qrpa/fun_base.py +193 -1
- qrpa/fun_excel.py +32 -7
- qrpa/shein_excel.py +1230 -1
- qrpa/shein_lib.py +281 -0
- {qrpa-1.0.24.dist-info → qrpa-1.0.25.dist-info}/METADATA +1 -1
- {qrpa-1.0.24.dist-info → qrpa-1.0.25.dist-info}/RECORD +9 -9
- {qrpa-1.0.24.dist-info → qrpa-1.0.25.dist-info}/WHEEL +0 -0
- {qrpa-1.0.24.dist-info → qrpa-1.0.25.dist-info}/top_level.txt +0 -0
qrpa/__init__.py
CHANGED
|
@@ -3,7 +3,8 @@ from .db_migrator import DatabaseMigrator, DatabaseConfig, RemoteConfig, create_
|
|
|
3
3
|
|
|
4
4
|
from .shein_ziniao import ZiniaoRunner
|
|
5
5
|
|
|
6
|
-
from .fun_base import log, send_exception, md5_string, hostname, get_safe_value, sanitize_filename, get_file_size, calculate_star_symbols
|
|
6
|
+
# from .fun_base import log, send_exception, md5_string, hostname, get_safe_value, sanitize_filename, get_file_size, calculate_star_symbols
|
|
7
|
+
from .fun_base import *
|
|
7
8
|
|
|
8
9
|
from .time_utils import TimeUtils
|
|
9
10
|
|
qrpa/fun_base.py
CHANGED
|
@@ -142,4 +142,196 @@ def calculate_star_symbols(rating):
|
|
|
142
142
|
empty_stars = 5 - full_stars
|
|
143
143
|
star_string = '★' * full_stars
|
|
144
144
|
star_string += '☆' * empty_stars
|
|
145
|
-
return star_string
|
|
145
|
+
return star_string
|
|
146
|
+
|
|
147
|
+
def remove_columns(matrix, indices):
|
|
148
|
+
"""
|
|
149
|
+
过滤二维列表,移除指定索引的列
|
|
150
|
+
|
|
151
|
+
参数:
|
|
152
|
+
matrix: 二维列表
|
|
153
|
+
indices: 需要移除的列索引列表
|
|
154
|
+
|
|
155
|
+
返回:
|
|
156
|
+
过滤后的二维列表
|
|
157
|
+
"""
|
|
158
|
+
# 创建要保留的索引集合(排除需要移除的索引)
|
|
159
|
+
indices_to_keep = set(range(len(matrix[0]))) - set(indices)
|
|
160
|
+
|
|
161
|
+
# 遍历每行,只保留不在indices中的列
|
|
162
|
+
return [[row[i] for i in indices_to_keep] for row in matrix]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def filter_columns(matrix, indices):
|
|
166
|
+
"""
|
|
167
|
+
过滤二维列表,只保留指定索引的列
|
|
168
|
+
|
|
169
|
+
参数:
|
|
170
|
+
matrix: 二维列表
|
|
171
|
+
indices: 需要保留的列索引列表
|
|
172
|
+
|
|
173
|
+
返回:
|
|
174
|
+
过滤后的二维列表
|
|
175
|
+
"""
|
|
176
|
+
# 转置矩阵,获取每一列
|
|
177
|
+
columns = list(zip(*matrix))
|
|
178
|
+
|
|
179
|
+
# 只保留指定索引的列
|
|
180
|
+
filtered_columns = [columns[i] for i in indices]
|
|
181
|
+
|
|
182
|
+
# 将过滤后的列转回二维列表
|
|
183
|
+
return [list(row) for row in zip(*filtered_columns)]
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# # 示例使用
|
|
187
|
+
# matrix = [
|
|
188
|
+
# [1, 2, 3, 4],
|
|
189
|
+
# [5, 6, 7, 8],
|
|
190
|
+
# [9, 10, 11, 12]
|
|
191
|
+
# ]
|
|
192
|
+
#
|
|
193
|
+
# # 只保留索引为 0 和 2 的列
|
|
194
|
+
# filtered = filter_columns(matrix, [0, 2])
|
|
195
|
+
# print(filtered) # 输出: [[1, 3], [5, 7], [9, 11]]
|
|
196
|
+
|
|
197
|
+
def add_column_to_2d_list(data, new_col, index=None):
|
|
198
|
+
"""
|
|
199
|
+
给二维列表增加一列数据
|
|
200
|
+
|
|
201
|
+
:param data: 原始二维列表,例如 [[1, 2], [3, 4]]
|
|
202
|
+
:param new_col: 要添加的新列数据,例如 [10, 20]
|
|
203
|
+
:param index: 插入位置,默认为最后一列之后;支持负数索引
|
|
204
|
+
:return: 增加新列后的二维列表
|
|
205
|
+
"""
|
|
206
|
+
if not data:
|
|
207
|
+
raise ValueError("原始数据为空")
|
|
208
|
+
if len(data) != len(new_col):
|
|
209
|
+
raise ValueError("新列长度必须与原始数据的行数相等")
|
|
210
|
+
|
|
211
|
+
new_data = []
|
|
212
|
+
for i, row in enumerate(data):
|
|
213
|
+
row = list(row) # 防止修改原始数据
|
|
214
|
+
insert_at = index if index is not None else len(row)
|
|
215
|
+
row.insert(insert_at, new_col[i])
|
|
216
|
+
new_data.append(row)
|
|
217
|
+
return new_data
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def add_prefixed_column(data, header, value):
|
|
221
|
+
"""
|
|
222
|
+
给二维列表增加第一列,第一行为 header,后面为 value。
|
|
223
|
+
|
|
224
|
+
:param data: 原始二维列表
|
|
225
|
+
:param header: 新列的标题
|
|
226
|
+
:param value: 新列内容(相同值)
|
|
227
|
+
:return: 增加新列后的二维列表
|
|
228
|
+
"""
|
|
229
|
+
if not data:
|
|
230
|
+
raise ValueError("原始数据不能为空")
|
|
231
|
+
|
|
232
|
+
new_col = [header] + [value] * (len(data) - 1)
|
|
233
|
+
return [[new_col[i]] + row for i, row in enumerate(data)]
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def add_suffixed_column(data, header, value):
|
|
237
|
+
"""
|
|
238
|
+
给二维列表增加第一列,第一行为 header,后面为 value。
|
|
239
|
+
|
|
240
|
+
:param data: 原始二维列表
|
|
241
|
+
:param header: 新列的标题
|
|
242
|
+
:param value: 新列内容(相同值)
|
|
243
|
+
:return: 增加新列后的二维列表
|
|
244
|
+
"""
|
|
245
|
+
if not data:
|
|
246
|
+
raise ValueError("原始数据不能为空")
|
|
247
|
+
|
|
248
|
+
new_col = [header] + [value] * (len(data) - 1)
|
|
249
|
+
return [row + [new_col[i]] for i, row in enumerate(data)]
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def merge_2d_lists_keep_first_header(data1, data2):
|
|
253
|
+
"""
|
|
254
|
+
合并两个二维列表,只保留第一个列表的标题(即第一行)。
|
|
255
|
+
|
|
256
|
+
:param data1: 第一个二维列表(包含标题)
|
|
257
|
+
:param data2: 第二个二维列表(包含标题)
|
|
258
|
+
:return: 合并后的二维列表
|
|
259
|
+
"""
|
|
260
|
+
if not data1 or not isinstance(data1, list):
|
|
261
|
+
raise ValueError("data1 不能为空并且必须是二维列表")
|
|
262
|
+
if not data2 or not isinstance(data2, list):
|
|
263
|
+
raise ValueError("data2 不能为空并且必须是二维列表")
|
|
264
|
+
|
|
265
|
+
header = data1[0]
|
|
266
|
+
rows1 = data1[1:]
|
|
267
|
+
rows2 = data2[1:]
|
|
268
|
+
|
|
269
|
+
return [header] + rows1 + rows2
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def insert_total_row(data, row_index=1, label="合计"):
|
|
273
|
+
"""
|
|
274
|
+
在指定行插入一行,第一列为 label,其余为空字符串。
|
|
275
|
+
|
|
276
|
+
:param data: 原始二维列表
|
|
277
|
+
:param row_index: 插入位置,默认插在第二行(索引1)
|
|
278
|
+
:param label: 第一列的标签内容,默认为 "合计"
|
|
279
|
+
:return: 新的二维列表
|
|
280
|
+
"""
|
|
281
|
+
if not data or not isinstance(data, list):
|
|
282
|
+
raise ValueError("data 不能为空并且必须是二维列表")
|
|
283
|
+
|
|
284
|
+
num_cols = len(data[0])
|
|
285
|
+
new_row = [label] + [""] * (num_cols - 1)
|
|
286
|
+
|
|
287
|
+
return data[:row_index] + [new_row] + data[row_index:]
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def insert_empty_column_after(data, col_index, new_header="单价成本"):
|
|
291
|
+
"""
|
|
292
|
+
在二维列表中指定列的后面插入一个新列,标题为 new_header,其余内容为空字符串。
|
|
293
|
+
|
|
294
|
+
:param data: 原始二维列表
|
|
295
|
+
:param col_index: 要插入的位置(在该列后面插入)
|
|
296
|
+
:param new_header: 新列的标题
|
|
297
|
+
:return: 新的二维列表
|
|
298
|
+
"""
|
|
299
|
+
if not data or not isinstance(data, list):
|
|
300
|
+
raise ValueError("data 不能为空且必须是二维列表")
|
|
301
|
+
|
|
302
|
+
new_data = []
|
|
303
|
+
for i, row in enumerate(data):
|
|
304
|
+
row = list(row) # 复制避免修改原数据
|
|
305
|
+
insert_value = new_header if i == 0 else ""
|
|
306
|
+
row.insert(col_index + 1, insert_value)
|
|
307
|
+
new_data.append(row)
|
|
308
|
+
|
|
309
|
+
return new_data
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def insert_empty_column_after_column_name(data, target_col_name, new_header="单价成本"):
|
|
313
|
+
"""
|
|
314
|
+
在指定列名对应的列后面插入一个新列,标题为 new_header,其余行为空字符串。
|
|
315
|
+
|
|
316
|
+
:param data: 原始二维列表
|
|
317
|
+
:param target_col_name: 要在哪一列之后插入(通过列标题匹配)
|
|
318
|
+
:param new_header: 插入的新列标题
|
|
319
|
+
:return: 新的二维列表
|
|
320
|
+
"""
|
|
321
|
+
if not data or not isinstance(data, list):
|
|
322
|
+
raise ValueError("data 不能为空且必须是二维列表")
|
|
323
|
+
|
|
324
|
+
header = data[0]
|
|
325
|
+
if target_col_name not in header:
|
|
326
|
+
raise ValueError(f"找不到列名:{target_col_name}")
|
|
327
|
+
|
|
328
|
+
col_index = header.index(target_col_name)
|
|
329
|
+
|
|
330
|
+
new_data = []
|
|
331
|
+
for i, row in enumerate(data):
|
|
332
|
+
row = list(row) # 防止修改原始数据
|
|
333
|
+
insert_value = new_header if i == 0 else ""
|
|
334
|
+
row.insert(col_index + 1, insert_value)
|
|
335
|
+
new_data.append(row)
|
|
336
|
+
|
|
337
|
+
return new_data
|
qrpa/fun_excel.py
CHANGED
|
@@ -542,7 +542,7 @@ def insert_fixed_scale_image(sheet, cell, image_path, scale=1.0):
|
|
|
542
542
|
|
|
543
543
|
return None
|
|
544
544
|
|
|
545
|
-
def InsertImageV2(sheet, columns=None, platform='shein', img_width=150, img_save_key=None, dir_name=None, cell_height_with_img=False):
|
|
545
|
+
def InsertImageV2(sheet, columns=None, platform='shein', img_width=150, img_save_key=None, dir_name=None, cell_height_with_img=False, start_row=2):
|
|
546
546
|
if not columns:
|
|
547
547
|
return
|
|
548
548
|
|
|
@@ -575,7 +575,7 @@ def InsertImageV2(sheet, columns=None, platform='shein', img_width=150, img_save
|
|
|
575
575
|
|
|
576
576
|
# 预计算所有单元格的合并区域信息 (优化点1)
|
|
577
577
|
area_map = {}
|
|
578
|
-
for row in range(
|
|
578
|
+
for row in range(start_row, last_row + 1):
|
|
579
579
|
log(f'计算 {row}/{last_row}') # 如果数据量非常大,这里的日志会影响性能,可以考虑优化
|
|
580
580
|
for col_letter in col_letter_map.values():
|
|
581
581
|
cell_ref = f'{col_letter}{row}'
|
|
@@ -616,7 +616,7 @@ def InsertImageV2(sheet, columns=None, platform='shein', img_width=150, img_save
|
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
# 处理图片插入 (优化点2)
|
|
619
|
-
for row in range(
|
|
619
|
+
for row in range(start_row, last_row + 1):
|
|
620
620
|
for img_col_name, col_letter in col_letter_map.items():
|
|
621
621
|
cell_ref = f'{col_letter}{row}'
|
|
622
622
|
cell_range = sheet.range(cell_ref)
|
|
@@ -1163,9 +1163,6 @@ def check_data(data):
|
|
|
1163
1163
|
log(len(row), row)
|
|
1164
1164
|
|
|
1165
1165
|
def write_data(excel_path, sheet_name, data, format_to_text_colunm=None):
|
|
1166
|
-
log('write_data入参:', excel_path, sheet_name, 'data', format_to_text_colunm)
|
|
1167
|
-
close_excel_file(excel_path)
|
|
1168
|
-
|
|
1169
1166
|
app, wb, sheet = open_excel(excel_path, sheet_name)
|
|
1170
1167
|
# 清空工作表中的所有数据
|
|
1171
1168
|
sheet.clear()
|
|
@@ -2065,6 +2062,21 @@ def format_to_number(sheet, columns=None, decimal_places=2):
|
|
|
2065
2062
|
# else:
|
|
2066
2063
|
# sheet.range(f'{col_name}:{col_name}').number_format = f'0.{"0" * decimal_places}'
|
|
2067
2064
|
|
|
2065
|
+
def hidden_columns(sheet, columns=None):
|
|
2066
|
+
if columns is None:
|
|
2067
|
+
return
|
|
2068
|
+
used_range_col = sheet.range('A1').expand('right')
|
|
2069
|
+
for j, cell in enumerate(used_range_col):
|
|
2070
|
+
col = j + 1
|
|
2071
|
+
col_name = index_to_column_name(col)
|
|
2072
|
+
col_val = sheet.range(f'{col_name}1').value
|
|
2073
|
+
if col_val is None:
|
|
2074
|
+
continue
|
|
2075
|
+
for c in columns:
|
|
2076
|
+
if c in col_val:
|
|
2077
|
+
log(f'设置[{c}] 隐藏')
|
|
2078
|
+
sheet.range(f'{col_name}:{col_name}').column_width = 0
|
|
2079
|
+
|
|
2068
2080
|
def column_to_right(sheet, columns=None):
|
|
2069
2081
|
if columns is None:
|
|
2070
2082
|
return
|
|
@@ -2080,7 +2092,7 @@ def column_to_right(sheet, columns=None):
|
|
|
2080
2092
|
# 水平对齐: # -4108:居中 # -4131:左对齐 # -4152:右对齐
|
|
2081
2093
|
# 垂直对齐: # -4108:居中 # -4160:顶部对齐 # -4107:底部对齐
|
|
2082
2094
|
# 所有列水平居中和垂直居中
|
|
2083
|
-
log(f'设置[{c}]
|
|
2095
|
+
log(f'设置[{c}] 水平右对齐')
|
|
2084
2096
|
sheet.range(f'{col_name}:{col_name}').api.HorizontalAlignment = -4152
|
|
2085
2097
|
sheet.range(f'{col_name}:{col_name}').api.VerticalAlignment = -4108
|
|
2086
2098
|
|
|
@@ -2121,6 +2133,16 @@ def beautify_title(sheet):
|
|
|
2121
2133
|
sheet.range(f'{col_name}:{col_name}').api.VerticalAlignment = -4108
|
|
2122
2134
|
sheet.autofit()
|
|
2123
2135
|
|
|
2136
|
+
def set_body_style(sheet, row_start, row_end=None):
|
|
2137
|
+
if row_end is None:
|
|
2138
|
+
row_end = get_last_used_row(sheet)
|
|
2139
|
+
|
|
2140
|
+
range = sheet.range(f'{row_start}:{row_end}')
|
|
2141
|
+
# 设置字体名称
|
|
2142
|
+
range.font.name = 'Calibri'
|
|
2143
|
+
# 设置字体大小
|
|
2144
|
+
range.font.size = 11
|
|
2145
|
+
|
|
2124
2146
|
def set_title_style(sheet, rows=2):
|
|
2125
2147
|
col = get_max_column_letter(sheet)
|
|
2126
2148
|
range = sheet.range(f'A1:{col}{rows}')
|
|
@@ -2700,3 +2722,6 @@ def get_excel_status(excel_path):
|
|
|
2700
2722
|
'operation_count': excel_lock_manager.get_operation_count(excel_path),
|
|
2701
2723
|
'has_lock' : excel_lock_manager.get_file_lock(excel_path).locked()
|
|
2702
2724
|
}
|
|
2725
|
+
|
|
2726
|
+
def get_last_used_row(sheet):
|
|
2727
|
+
return sheet.used_range.last_cell.row
|