smartpush 1.0.9__py3-none-any.whl → 1.1.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.
- smartpush/export/basic/ExcelExportChecker.py +58 -23
- smartpush/test.py +6 -6
- {smartpush-1.0.9.dist-info → smartpush-1.1.1.dist-info}/METADATA +1 -1
- {smartpush-1.0.9.dist-info → smartpush-1.1.1.dist-info}/RECORD +6 -6
- {smartpush-1.0.9.dist-info → smartpush-1.1.1.dist-info}/WHEEL +0 -0
- {smartpush-1.0.9.dist-info → smartpush-1.1.1.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,9 @@
|
|
1
|
-
import contextlib
|
2
1
|
import os
|
3
2
|
import re
|
3
|
+
import warnings
|
4
4
|
from io import BytesIO
|
5
5
|
from urllib.parse import unquote
|
6
6
|
import pandas as pd
|
7
|
-
import numpy as np
|
8
|
-
import warnings
|
9
7
|
from requests import request
|
10
8
|
|
11
9
|
"""
|
@@ -25,6 +23,13 @@ def read_excel_from_oss(url="", method="get"):
|
|
25
23
|
print(f"读取oss报错 {url} 时出错:{e}")
|
26
24
|
|
27
25
|
|
26
|
+
def read_excel_data(excel_data, **kwargs):
|
27
|
+
with warnings.catch_warnings():
|
28
|
+
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
29
|
+
dfs = pd.read_excel(excel_data, sheet_name=None, engine="openpyxl", na_filter=False, **kwargs)
|
30
|
+
return dfs
|
31
|
+
|
32
|
+
|
28
33
|
def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
29
34
|
"""excel内容并写入到内存dict中
|
30
35
|
:param excel_data:excel的io对象, 参数和file_name互斥
|
@@ -35,19 +40,17 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
|
35
40
|
pass
|
36
41
|
elif file_name is not None:
|
37
42
|
excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
|
38
|
-
|
39
|
-
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
40
|
-
df = pd.read_excel(excel_data, engine="openpyxl", **kwargs)
|
43
|
+
dfs = read_excel_data(excel_data)
|
41
44
|
# 将DataFrame转换为字典,以行为单位存储数据
|
42
45
|
row_dict = {} # 创建一个空字典来存储按行转换的数据
|
43
|
-
for index, row in
|
46
|
+
for index, row in dfs.iterrows(): # 遍历DataFrame中的每一行
|
44
47
|
row_dict[index] = row.to_dict() # 将每一行转换为字典并存储在row_dict中
|
45
48
|
return row_dict
|
46
49
|
except Exception as e:
|
47
50
|
print(f"excel写入dict时出错:{e}")
|
48
51
|
|
49
52
|
|
50
|
-
def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
|
53
|
+
def read_excel_and_write_to_list(excel_data=None, sheet_name=None, file_name=None, **kwargs):
|
51
54
|
"""excel内容并写入到内存list中
|
52
55
|
:param excel_data:excel的io对象, 参数和file_name互斥
|
53
56
|
:file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
|
@@ -78,6 +81,7 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
|
|
78
81
|
storage_options:存储选项。
|
79
82
|
dtype_backend:数据类型后端。
|
80
83
|
engine_kwargs:传递给引擎的额外参数。
|
84
|
+
@param sheet_name:
|
81
85
|
|
82
86
|
|
83
87
|
"""
|
@@ -87,11 +91,13 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
|
|
87
91
|
elif file_name is not None:
|
88
92
|
excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
94
|
+
dfs = read_excel_data(excel_data)
|
95
|
+
rows_list = []
|
96
|
+
# 多sheet处理
|
97
|
+
for name, df in dfs.items():
|
98
|
+
rows_list.append(df.values.tolist())
|
99
|
+
if len(dfs) <= 1:
|
100
|
+
rows_list = rows_list[0]
|
95
101
|
return rows_list
|
96
102
|
except Exception as e:
|
97
103
|
print(f"excel写入list时出错:{e}")
|
@@ -108,23 +114,35 @@ def read_excel_and_write_to_csv(excel_data, file_name, **kwargs):
|
|
108
114
|
print(f"excel写入csv时出错:{e}")
|
109
115
|
|
110
116
|
|
111
|
-
def
|
117
|
+
def read_excel_data_for_oss_write_to_dict(oss, **kwargs) -> dict:
|
112
118
|
"""
|
113
119
|
1、根据oss link 直接读出 dict-list
|
114
|
-
2、支持多sheet,默认
|
120
|
+
2、支持多sheet,默认sheet_name =None查全部
|
115
121
|
3、返回dict结构 {'sheet_name':[rows_list]}
|
116
122
|
"""
|
117
123
|
try:
|
118
|
-
|
119
|
-
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
120
|
-
dfs = pd.read_excel(read_excel_from_oss(oss), sheet_name, engine="openpyxl", **kwargs)
|
124
|
+
dfs = read_excel_data(read_excel_from_oss(oss))
|
121
125
|
result = {}
|
122
126
|
for sheet_name, df in dfs.items():
|
123
127
|
rows_list = df.values.tolist()
|
124
128
|
result[sheet_name] = rows_list
|
125
129
|
return result
|
126
130
|
except Exception as e:
|
127
|
-
print(f"excel
|
131
|
+
print(f"excel生成dict出错:{e}")
|
132
|
+
|
133
|
+
|
134
|
+
def read_excel_header_for_oss_write_to_list(oss) -> list:
|
135
|
+
"""
|
136
|
+
1、根据oss link 直接读出excel的头列 list
|
137
|
+
"""
|
138
|
+
try:
|
139
|
+
dfs = read_excel_data(read_excel_from_oss(oss))
|
140
|
+
result = []
|
141
|
+
for sheet_name, df in dfs.items():
|
142
|
+
result.append(df.keys().values.tolist())
|
143
|
+
return result
|
144
|
+
except Exception as e:
|
145
|
+
print(f"excel生成header-dict出错:{e}")
|
128
146
|
|
129
147
|
|
130
148
|
def check_excel(check_type="content", **kwargs):
|
@@ -152,7 +170,8 @@ def check_excel(check_type="content", **kwargs):
|
|
152
170
|
expected_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]))
|
153
171
|
flag1, content_result = check_excel_content(actual=actual_content, expected=expected_content)
|
154
172
|
flag2, name_result = check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
155
|
-
|
173
|
+
flag3 = check_excel_header(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
174
|
+
return all([flag1, flag2, flag3]), {"文件名称": name_result, "导出内容": content_result}
|
156
175
|
else:
|
157
176
|
return False, f"不支持此类型: {check_type}"
|
158
177
|
except Exception as e:
|
@@ -169,6 +188,7 @@ comparison_functions = {
|
|
169
188
|
else check_excel_content(kwargs["actual_oss"], kwargs["expected_oss"]),
|
170
189
|
# excelName
|
171
190
|
"excelName": lambda kwargs: check_excel_name(kwargs["actual_oss"], kwargs["expected_oss"]),
|
191
|
+
'header': lambda kwargs: check_excel_header(kwargs["actual_oss"], kwargs["expected_oss"]),
|
172
192
|
# 全部
|
173
193
|
"all": lambda kwargs: check_excel_all(kwargs["actual_oss"], kwargs["expected_oss"])
|
174
194
|
}
|
@@ -213,7 +233,9 @@ def check_excel_all(actual_oss, expected_oss):
|
|
213
233
|
"""
|
214
234
|
flag1, content_result = check_excel_content_form_oss(actual_oss, expected_oss)
|
215
235
|
flag2, name_result = check_excel_name(actual_oss, expected_oss)
|
216
|
-
|
236
|
+
flag3 = check_excel_header(actual_oss, expected_oss)
|
237
|
+
return all([flag1, flag2, flag3]), {"文件名称": name_result, "导出内容": content_result,
|
238
|
+
"校验结果": [flag1, flag2, flag3]}
|
217
239
|
|
218
240
|
|
219
241
|
def check_excel_name(actual_oss, expected_oss):
|
@@ -251,7 +273,9 @@ def check_excel_content(actual, expected):
|
|
251
273
|
errors.append("excel内容-预期和实际行数相等,为" + str(actual_num) + "行")
|
252
274
|
else:
|
253
275
|
errors.append(
|
254
|
-
"excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(
|
276
|
+
"excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(
|
277
|
+
actual_num) + "预期: " + str(
|
278
|
+
expected_num))
|
255
279
|
# 断言不匹配行
|
256
280
|
if check_row >= 0:
|
257
281
|
num = len(expected)
|
@@ -269,6 +293,18 @@ def check_excel_content(actual, expected):
|
|
269
293
|
return False, [e]
|
270
294
|
|
271
295
|
|
296
|
+
def check_excel_header(actual_oss, expected_oss):
|
297
|
+
"""
|
298
|
+
比较两个文档第一列的header是否一致
|
299
|
+
@param actual_oss:
|
300
|
+
@param expected_oss:
|
301
|
+
@return:
|
302
|
+
"""
|
303
|
+
actual, expected = read_excel_data_for_oss_write_to_dict(actual_oss), read_excel_data_for_oss_write_to_dict(
|
304
|
+
expected_oss)
|
305
|
+
return actual == expected
|
306
|
+
|
307
|
+
|
272
308
|
def del_temp_file(file_name=""):
|
273
309
|
"""删除temp下临时文件"""
|
274
310
|
file_path = os.path.join(os.path.dirname(os.getcwd()) + "/temp_file/" + file_name)
|
@@ -279,4 +315,3 @@ def del_temp_file(file_name=""):
|
|
279
315
|
print(f"文件 {file_path} 不存在。")
|
280
316
|
except Exception as e:
|
281
317
|
print(f"删除文件 {file_path} 时出错:{e}")
|
282
|
-
|
smartpush/test.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
from smartpush.export.basic.ExcelExportChecker import
|
1
|
+
from smartpush.export.basic.ExcelExportChecker import *
|
2
2
|
from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
|
3
3
|
|
4
|
+
import urllib3
|
5
|
+
|
4
6
|
if __name__ == '__main__':
|
5
7
|
# print(check_excel_for_lu("content",actual_oss="https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2_prod/2025-01-20/fcb98e2965314ef2862db65760dcce1f/ab%E5%BC%B9%E7%AA%97%E6%B4%BB%E5%8A%A8-%E8%BD%AC%E5%8C%96%E7%8E%87%E8%8E%B7%E8%83%9C%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx",expected_oss="https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2_prod/2025-01-20/fcb98e2965314ef2862db65760dcce1f/ab%E5%BC%B9%E7%AA%97%E6%B4%BB%E5%8A%A8-%E8%BD%AC%E5%8C%96%E7%8E%87%E8%8E%B7%E8%83%9C%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx"))
|
6
|
-
|
7
|
-
|
8
8
|
_id = 10901
|
9
9
|
url = "https://test.smartpushedm.com/api-em-ec2/bulkOps/query"
|
10
10
|
requestHeaders = {
|
@@ -12,7 +12,7 @@ if __name__ == '__main__':
|
|
12
12
|
'Content-Type': 'application/json'}
|
13
13
|
requestParams = {'page': 1, 'pageSize': 10, 'type': 'EXPORT', 'status': None, 'startTime': None, 'endTime': None}
|
14
14
|
oss=get_oss_address_with_retry(_id, url, requestHeaders, requestParams, tries=1, delay=1, backoff=1)
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
check_excel_for_lu("all",oss,oss)
|
16
|
+
# oss = "https://cdn.smartpushedm.com/material_sf/2025-02-19/c70bb6f3588b4c89bde6ed75813ea4f3/%E5%AF%BC%E5%87%BA%E5%85%A8%E9%83%A8%E5%AE%A2%E6%88%B7.csv"
|
17
|
+
# eexcelxcel =read_excel_and_write_to_list(read_excel_from_oss(oss))
|
18
18
|
print(eexcelxcel)
|
@@ -1,13 +1,13 @@
|
|
1
1
|
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
2
|
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
3
|
-
smartpush/test.py,sha256=
|
3
|
+
smartpush/test.py,sha256=FTfTwcJEZFPz_Rq8pAooOW_qBN1sbVQbm2htF8mgqDo,2939
|
4
4
|
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
-
smartpush/export/basic/ExcelExportChecker.py,sha256=
|
5
|
+
smartpush/export/basic/ExcelExportChecker.py,sha256=Y4agi5F8j1sIgM10Z3yKKs6y7rg4p6-6GSyKMpEITzs,13173
|
6
6
|
smartpush/export/basic/GetOssUrl.py,sha256=O2-HtcYzbabck9dKgLu8ga21_AiyDIzgdfoDgvqBY3c,1541
|
7
7
|
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
8
8
|
smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
|
9
9
|
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
smartpush-1.
|
11
|
-
smartpush-1.
|
12
|
-
smartpush-1.
|
13
|
-
smartpush-1.
|
10
|
+
smartpush-1.1.1.dist-info/METADATA,sha256=5tCwRmx5MPLlVdUC695sEQEUDgcVr5TIZJeSVakIJr4,145
|
11
|
+
smartpush-1.1.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
12
|
+
smartpush-1.1.1.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
13
|
+
smartpush-1.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|