smartpush 1.1.3__py3-none-any.whl → 1.1.5__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 +85 -61
- smartpush/export/basic/GetOssUrl.py +65 -5
- smartpush/export/basic/ReadExcel.py +41 -18
- smartpush/test.py +12 -2
- {smartpush-1.1.3.dist-info → smartpush-1.1.5.dist-info}/METADATA +1 -1
- smartpush-1.1.5.dist-info/RECORD +14 -0
- smartpush-1.1.3.dist-info/RECORD +0 -14
- {smartpush-1.1.3.dist-info → smartpush-1.1.5.dist-info}/WHEEL +0 -0
- {smartpush-1.1.3.dist-info → smartpush-1.1.5.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,4 @@
|
|
1
|
+
import copy
|
1
2
|
import json
|
2
3
|
from urllib.parse import unquote
|
3
4
|
|
@@ -24,17 +25,21 @@ def check_excel(check_type="content", **kwargs):
|
|
24
25
|
return check_excel_content(actual=kwargs["actual"], expected=kwargs["expected"])
|
25
26
|
else:
|
26
27
|
return check_excel_content(
|
27
|
-
actual=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"])
|
28
|
-
|
28
|
+
actual=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"]),
|
29
|
+
**kwargs),
|
30
|
+
expected=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]),
|
31
|
+
**kwargs)
|
29
32
|
)
|
30
33
|
elif check_type == "excelName":
|
31
34
|
return check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
32
35
|
elif check_type == "all":
|
33
|
-
actual_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"])
|
34
|
-
|
36
|
+
actual_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"]),
|
37
|
+
**kwargs)
|
38
|
+
expected_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]),
|
39
|
+
**kwargs)
|
35
40
|
flag1, content_result = check_excel_content(actual=actual_content, expected=expected_content)
|
36
41
|
flag2, name_result = check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
37
|
-
flag3, header_result = check_excel_header(actual=actual_content, expected=expected_content)
|
42
|
+
flag3, header_result = check_excel_header(actual=actual_content, expected=expected_content, **kwargs)
|
38
43
|
return all([flag1, flag2, flag3]), {"文件名称": name_result, "导出内容": content_result, "表头比较:": header_result}
|
39
44
|
else:
|
40
45
|
return False, f"不支持此类型: {check_type}"
|
@@ -43,51 +48,51 @@ def check_excel(check_type="content", **kwargs):
|
|
43
48
|
return False, [e]
|
44
49
|
|
45
50
|
|
46
|
-
# 定义比较类型和对应处理函数的映射
|
47
|
-
comparison_functions = {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
51
|
+
# # 定义比较类型和对应处理函数的映射
|
52
|
+
# comparison_functions = {
|
53
|
+
# # 内容
|
54
|
+
# "content": lambda kwargs: check_excel_content(kwargs["actual"], kwargs["expected"]),
|
55
|
+
# # excelName
|
56
|
+
# "excelName": lambda kwargs: check_excel_name(kwargs["actual_oss"], kwargs["expected_oss"]),
|
57
|
+
# 'header': lambda kwargs: check_excel_header(kwargs["actual"], kwargs["expected"]),
|
58
|
+
# # 全部
|
59
|
+
# "all": lambda kwargs: check_excel_all(kwargs["actual_oss"], kwargs["expected_oss"])
|
60
|
+
# }
|
61
|
+
#
|
62
|
+
#
|
63
|
+
# def check_excel_for_lu(check_type="content", **kwargs):
|
64
|
+
# """对比excel
|
65
|
+
# :param: type: 需要对比类型,
|
66
|
+
# 枚举:
|
67
|
+
# content:对比两表格内容
|
68
|
+
# 方式1:传参actual_oss和expected_oss,参数类型str,url
|
69
|
+
# 放松1:传参actual和expected,参数类型list or dict
|
70
|
+
# excelName: 对比两表格文件名称,传oss链接
|
71
|
+
# all: 对比所有内容,传oss链接
|
72
|
+
# """
|
73
|
+
# try:
|
74
|
+
# # 根据 check_type 获取对应的处理函数
|
75
|
+
# compare_func = comparison_functions.get(check_type)
|
76
|
+
# if compare_func:
|
77
|
+
# return compare_func(kwargs)
|
78
|
+
# else:
|
79
|
+
# return False, f"不支持此类型: {check_type}"
|
80
|
+
# except KeyError as ke:
|
81
|
+
# # raise ke
|
82
|
+
# print(f"类型对应参数缺失异常:{ke}")
|
83
|
+
# return False, [str(ke)]
|
84
|
+
# except Exception as e:
|
85
|
+
# print(f"对比 Excel 异常:{e}")
|
86
|
+
# return False, [str(e)]
|
56
87
|
|
57
88
|
|
58
|
-
def
|
59
|
-
"""对比excel
|
60
|
-
:param: type: 需要对比类型,
|
61
|
-
枚举:
|
62
|
-
content:对比两表格内容
|
63
|
-
方式1:传参actual_oss和expected_oss,参数类型str,url
|
64
|
-
放松1:传参actual和expected,参数类型list or dict
|
65
|
-
excelName: 对比两表格文件名称,传oss链接
|
66
|
-
all: 对比所有内容,传oss链接
|
67
|
-
"""
|
68
|
-
try:
|
69
|
-
# 根据 check_type 获取对应的处理函数
|
70
|
-
compare_func = comparison_functions.get(check_type)
|
71
|
-
if compare_func:
|
72
|
-
return compare_func(kwargs)
|
73
|
-
else:
|
74
|
-
return False, f"不支持此类型: {check_type}"
|
75
|
-
except KeyError as ke:
|
76
|
-
# raise ke
|
77
|
-
print(f"类型对应参数缺失异常:{ke}")
|
78
|
-
return False, [str(ke)]
|
79
|
-
except Exception as e:
|
80
|
-
print(f"对比 Excel 异常:{e}")
|
81
|
-
return False, [str(e)]
|
82
|
-
|
83
|
-
|
84
|
-
def check_excel_content_form_dict(actual, expected):
|
89
|
+
def check_excel_content_form_dict(actual, expected, **kwargs):
|
85
90
|
"""
|
86
91
|
通过 OSS URL 比较 Excel 内容,支持多sheet并且包含表头
|
87
92
|
"""
|
88
|
-
|
89
|
-
expected)
|
90
|
-
return check_excel_content(actual
|
93
|
+
actual, expected = read_excel_and_write_to_dict(actual, **kwargs), read_excel_and_write_to_dict(
|
94
|
+
expected, **kwargs)
|
95
|
+
return check_excel_content(actual, expected)
|
91
96
|
|
92
97
|
|
93
98
|
def check_excel_content_form_list(actual, expected):
|
@@ -102,13 +107,31 @@ def check_excel_all(actual_oss, expected_oss):
|
|
102
107
|
"""
|
103
108
|
校验所有内容
|
104
109
|
"""
|
105
|
-
|
106
|
-
|
110
|
+
file_type = check_and_get_file_suffix_name(expected_oss, actual_oss)
|
111
|
+
actual, expected = read_excel_from_oss(actual_oss), read_excel_from_oss(expected_oss)
|
112
|
+
actual_data_copy = copy.deepcopy(actual)
|
113
|
+
expected_data_copy = copy.deepcopy(expected)
|
114
|
+
flag1, content_result = check_excel_content_form_dict(actual, expected, type=file_type)
|
107
115
|
flag2, name_result = check_excel_name(actual_oss, expected_oss)
|
108
|
-
flag3, header_result = check_excel_header(
|
109
|
-
return all([flag1, flag2
|
110
|
-
|
111
|
-
|
116
|
+
flag3, header_result = check_excel_header(actual_data_copy,expected_data_copy, type=file_type)
|
117
|
+
return all([flag1, flag2]), json.dumps({f"文件名称-{flag1}": name_result, f"导出内容-{flag2}": content_result,f"表头校验-{flag3}": header_result},
|
118
|
+
ensure_ascii=False)
|
119
|
+
|
120
|
+
|
121
|
+
def check_and_get_file_suffix_name(actual_oss, expected_oss) -> str:
|
122
|
+
"""
|
123
|
+
校验并获取oss的后缀类型
|
124
|
+
@param actual_oss:
|
125
|
+
@param expected_oss:
|
126
|
+
@return:
|
127
|
+
"""
|
128
|
+
actual_file_suffix_name = get_file_suffix_name(actual_oss)
|
129
|
+
expected_file_suffix_name = get_file_suffix_name(expected_oss)
|
130
|
+
try:
|
131
|
+
assert actual_file_suffix_name == expected_file_suffix_name
|
132
|
+
return actual_file_suffix_name
|
133
|
+
except Exception:
|
134
|
+
raise Exception("oss文件类型不一致,请检查oss链接是否为相同类型")
|
112
135
|
|
113
136
|
|
114
137
|
def check_excel_name(actual_oss, expected_oss):
|
@@ -169,7 +192,7 @@ def check_excel_content(actual, expected):
|
|
169
192
|
return False, [e]
|
170
193
|
|
171
194
|
|
172
|
-
def check_excel_header(actual, expected):
|
195
|
+
def check_excel_header(actual, expected, **kwargs):
|
173
196
|
"""
|
174
197
|
比较两个文档第一列的header是否一致
|
175
198
|
@param actual:
|
@@ -179,17 +202,18 @@ def check_excel_header(actual, expected):
|
|
179
202
|
"""
|
180
203
|
try:
|
181
204
|
if all([isinstance(actual, str), isinstance(expected, str)]):
|
182
|
-
|
183
|
-
|
205
|
+
actual1, expected1 = read_excel_header(read_excel_from_oss(actual), **kwargs), read_excel_header(
|
206
|
+
read_excel_from_oss(
|
207
|
+
expected), **kwargs)
|
184
208
|
else:
|
185
|
-
|
186
|
-
|
187
|
-
|
209
|
+
actual1, expected1 = read_excel_header(actual, **kwargs), read_excel_header(expected, **kwargs)
|
210
|
+
try:
|
211
|
+
assert actual1 == expected1
|
188
212
|
return True, "表头校验值与顺序一致"
|
189
|
-
|
190
|
-
return False,"表头校验值与顺序失败"
|
191
|
-
except:
|
192
|
-
return False, "表头校验异常"
|
213
|
+
except Exception as e:
|
214
|
+
return False, f"表头校验值与顺序失败 {e}"
|
215
|
+
except Exception as e:
|
216
|
+
return False, f"表头校验异常 {e}"
|
193
217
|
|
194
218
|
|
195
219
|
def del_temp_file(file_name=""):
|
@@ -1,9 +1,21 @@
|
|
1
|
-
import
|
2
|
-
from retry import retry
|
1
|
+
# from retry import retry
|
3
2
|
import json
|
3
|
+
|
4
|
+
import requests
|
5
|
+
from tenacity import retry, stop_after_attempt, wait_fixed,RetryError
|
6
|
+
|
4
7
|
from smartpush.utils.StringUtils import StringUtils
|
5
8
|
|
6
9
|
|
10
|
+
# 用于技术第几次重试,无需修改
|
11
|
+
def log_attempt(retry_state):
|
12
|
+
"""
|
13
|
+
回调函数,在每次重试时记录并打印重试次数
|
14
|
+
"""
|
15
|
+
attempt_number = retry_state.attempt_number
|
16
|
+
print(f"当前重试次数: {attempt_number}")
|
17
|
+
|
18
|
+
|
7
19
|
def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kwargs) -> str:
|
8
20
|
"""
|
9
21
|
创建带有动态重试配置的获取 OSS 地址
|
@@ -14,19 +26,26 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
|
|
14
26
|
:param requestHeader:
|
15
27
|
:return: 带有重试配置的获取 OSS 地址的
|
16
28
|
"""
|
29
|
+
tries = kwargs.get('tries', 10) # 重试次数
|
30
|
+
delay = kwargs.get('delay', 2)
|
31
|
+
|
17
32
|
|
18
|
-
@retry(tries
|
33
|
+
@retry(stop=stop_after_attempt(tries), wait=wait_fixed(delay), after=log_attempt)
|
19
34
|
def get_oss_address():
|
35
|
+
_url = url + '/bulkOps/query'
|
36
|
+
result = None
|
20
37
|
if StringUtils.is_empty(target_id):
|
21
38
|
print(f"缺少参数:target_id")
|
22
39
|
return
|
23
40
|
try:
|
24
|
-
response = requests.request(url=
|
41
|
+
response = requests.request(url=_url, headers=requestHeader, data=json.dumps(requestParam),
|
42
|
+
method="post")
|
25
43
|
response.raise_for_status()
|
26
44
|
result = response.json()
|
27
45
|
id_url_dict = {item["id"]: item["url"] for item in result["resultData"]["datas"]}
|
28
46
|
if target_id in id_url_dict:
|
29
47
|
if len(id_url_dict[target_id]) == 1:
|
48
|
+
print(f"{target_id} oss链接为:{id_url_dict[target_id][0]}")
|
30
49
|
return id_url_dict[target_id][0]
|
31
50
|
else:
|
32
51
|
raise ValueError(f"存在多条 id 为 {target_id} 的记录,记录为:{id_url_dict[target_id]}")
|
@@ -34,4 +53,45 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
|
|
34
53
|
raise ValueError(f"未找到 id 为 {target_id} 的记录,未包含有效的 OSS 地址,")
|
35
54
|
except (KeyError, json.JSONDecodeError) as e:
|
36
55
|
raise ValueError(f"响应数据格式错误,响应结果: {result},异常: {e}")
|
37
|
-
|
56
|
+
except requests.RequestException as e:
|
57
|
+
print(f"请求发生异常: {e},正在重试...")
|
58
|
+
raise
|
59
|
+
|
60
|
+
def cancel_export_file(_target_id):
|
61
|
+
"""
|
62
|
+
用于失败后取消导出
|
63
|
+
:param _target_id:
|
64
|
+
:return:
|
65
|
+
"""
|
66
|
+
cancel_url = url + '/bulkOps/cancel'
|
67
|
+
response = requests.request(url=cancel_url, headers=requestHeader, params={'id': _target_id}, method="get")
|
68
|
+
response.raise_for_status()
|
69
|
+
result = response.json()
|
70
|
+
print(f"获取Oss Url失败,取消 {_target_id} 的导出记录,响应:{result}")
|
71
|
+
return result
|
72
|
+
|
73
|
+
try:
|
74
|
+
return get_oss_address()
|
75
|
+
except Exception as e:
|
76
|
+
# print(f"最终失败,错误信息: {e}")
|
77
|
+
if isinstance(e, RetryError):
|
78
|
+
cancel_export_file(target_id)
|
79
|
+
return None
|
80
|
+
|
81
|
+
|
82
|
+
if __name__ == '__main__':
|
83
|
+
url = "https://test.smartpushedm.com/api-em-ec2"
|
84
|
+
requestHeader = {
|
85
|
+
"cookie": "osudb_appid=SMARTPUSH;osudb_oar=#01#SID0000122BBLon+0gwvStide+qtdJAK57ZSK1ty+iW8b7tv/Uwl6Zo4gDfUg6B83n+jgqTVjoZ5qRGyRsuLaXc9woDN2WRh3mu1yn7anglBmaFoemhCy/ttS8nqv/y0kj8khbu6mtBmQrseNfnO/Mir8PQP+S;osudb_subappid=1;osudb_uid=4213785247;ecom_http_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDI1Mjk2NTQsImp0aSI6ImM2MTA4MGJkLTU4MGUtNDJiNi05NzU5LTU0ZTNmZDExZDA4OSIsInVzZXJJbmZvIjp7ImlkIjowLCJ1c2VySWQiOiI0MjEzNzg1MjQ3IiwidXNlcm5hbWUiOiIiLCJlbWFpbCI6ImZlbGl4LnNoYW9Ac2hvcGxpbmVhcHAuY29tIiwidXNlclJvbGUiOiJvd25lciIsInBsYXRmb3JtVHlwZSI6Nywic3ViUGxhdGZvcm0iOjEsInBob25lIjoiIiwibGFuZ3VhZ2UiOiJ6aC1oYW5zLWNuIiwiYXV0aFR5cGUiOiIiLCJhdHRyaWJ1dGVzIjp7ImNvdW50cnlDb2RlIjoiQ04iLCJjdXJyZW5jeSI6IkpQWSIsImN1cnJlbmN5U3ltYm9sIjoiSlDCpSIsImRvbWFpbiI6InNtYXJ0cHVzaDQubXlzaG9wbGluZXN0Zy5jb20iLCJsYW5ndWFnZSI6ImVuIiwibWVyY2hhbnRFbWFpbCI6ImZlbGl4LnNoYW9Ac2hvcGxpbmUuY29tIiwibWVyY2hhbnROYW1lIjoiU21hcnRQdXNoNF9lYzJf6Ieq5Yqo5YyW5bqX6ZO6IiwicGhvbmUiOiIiLCJzY29wZUNoYW5nZWQiOmZhbHNlLCJzdGFmZkxhbmd1YWdlIjoiemgtaGFucy1jbiIsInN0YXR1cyI6MCwidGltZXpvbmUiOiJBc2lhL01hY2FvIn0sInN0b3JlSWQiOiIxNjQ0Mzk1OTIwNDQ0IiwiaGFuZGxlIjoic21hcnRwdXNoNCIsImVudiI6IkNOIiwic3RlIjoiIiwidmVyaWZ5IjoiIn0sImxvZ2luVGltZSI6MTczOTkzNzY1NDc2Mywic2NvcGUiOlsiZW1haWwtbWFya2V0IiwiY29va2llIiwic2wtZWNvbS1lbWFpbC1tYXJrZXQtbmV3LXRlc3QiLCJlbWFpbC1tYXJrZXQtbmV3LWRldi1mcyIsImFwaS11Yy1lYzIiLCJhcGktc3UtZWMyIiwiYXBpLWVtLWVjMiIsImZsb3ctcGx1Z2luIl0sImNsaWVudF9pZCI6ImVtYWlsLW1hcmtldCJ9.X2Birt-jiWILAvEjjwknUchil2ys8Y11omeRYgZ3K0I;",
|
86
|
+
"Content-Type": "application/json"
|
87
|
+
}
|
88
|
+
requestParam = {
|
89
|
+
"page": 1,
|
90
|
+
"pageSize": 20,
|
91
|
+
"type": "EXPORT",
|
92
|
+
"status": None,
|
93
|
+
"startTime": 1740033265288,
|
94
|
+
"endTime": 1740044065288
|
95
|
+
}
|
96
|
+
id = "2334659"
|
97
|
+
get_oss_address_with_retry(2334659, url, requestHeader, requestParam)
|
@@ -1,16 +1,14 @@
|
|
1
1
|
import io
|
2
|
-
import json
|
3
2
|
import os
|
4
3
|
import re
|
5
4
|
import warnings
|
6
5
|
from io import BytesIO
|
7
|
-
from typing import Dict, Any
|
8
|
-
|
9
6
|
import pandas as pd
|
10
|
-
from pandas import DataFrame
|
11
7
|
from requests import request
|
12
8
|
|
13
9
|
warnings.simplefilter("ignore")
|
10
|
+
excel_extensions = ['.xlsb', '.xlsx', '.xlsm', '.xls', '.xltx', '.xltm', '.xlam', None]
|
11
|
+
csv_extensions = ['.csv']
|
14
12
|
|
15
13
|
|
16
14
|
def read_excel_from_oss(url="", method="get"):
|
@@ -26,23 +24,31 @@ def read_excel_from_oss(url="", method="get"):
|
|
26
24
|
|
27
25
|
def read_excel_header(excel_data, **kwargs) -> list:
|
28
26
|
"""
|
29
|
-
1
|
27
|
+
1、读出excel的头列 list
|
30
28
|
"""
|
31
29
|
try:
|
32
|
-
dfs =
|
30
|
+
dfs = read_excel_csv_data(excel_data,**kwargs)
|
33
31
|
result = []
|
34
|
-
|
35
|
-
|
32
|
+
if kwargs['type'] in excel_extensions:
|
33
|
+
for sheet_name, df in dfs.items():
|
34
|
+
result.append(df.keys().values.tolist())
|
35
|
+
else:
|
36
|
+
result = dfs.keys().values.tolist()
|
36
37
|
return result
|
37
38
|
except Exception as e:
|
38
39
|
print(f"excel生成header-list出错:{e}")
|
40
|
+
raise
|
39
41
|
|
40
42
|
|
41
|
-
def
|
43
|
+
def read_excel_csv_data(excel_data, **kwargs):
|
42
44
|
with warnings.catch_warnings():
|
43
45
|
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
44
|
-
|
45
|
-
|
46
|
+
if kwargs['type'] in excel_extensions:
|
47
|
+
dfs = pd.read_excel(excel_data, sheet_name=None, na_filter=False) if isinstance(excel_data,
|
48
|
+
io.BytesIO) \
|
49
|
+
else excel_data
|
50
|
+
else:
|
51
|
+
dfs = pd.read_csv(excel_data, na_filter=False)
|
46
52
|
return dfs
|
47
53
|
|
48
54
|
|
@@ -56,11 +62,14 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
|
56
62
|
pass
|
57
63
|
elif file_name is not None:
|
58
64
|
excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
|
59
|
-
dfs =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
dfs = read_excel_csv_data(excel_data, **kwargs)
|
66
|
+
if kwargs['type'] in excel_extensions:
|
67
|
+
# 将DataFrame转换为字典,以行为单位存储数据
|
68
|
+
row_dict = {} # 创建一个空字典来存储按行转换的数据
|
69
|
+
for sheet_name, row in dfs.items():
|
70
|
+
row_dict[sheet_name] = row.to_dict(orient='records')
|
71
|
+
else:
|
72
|
+
row_dict = dfs.to_dict()
|
64
73
|
return row_dict
|
65
74
|
except Exception as e:
|
66
75
|
print(f"excel写入dict时出错:{e}")
|
@@ -76,7 +85,7 @@ def read_excel_and_write_to_list(excel_data=None, sheet_name=None, file_name=Non
|
|
76
85
|
pass
|
77
86
|
elif file_name is not None:
|
78
87
|
excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
|
79
|
-
dfs =
|
88
|
+
dfs = read_excel_csv_data(excel_data, **kwargs)
|
80
89
|
rows_list = []
|
81
90
|
# 多sheet处理
|
82
91
|
for name, df in dfs.items():
|
@@ -106,7 +115,7 @@ def read_excel_data_for_oss_write_to_dict(oss, **kwargs) -> dict:
|
|
106
115
|
3、返回dict结构 {'sheet_name':[rows_list]}
|
107
116
|
"""
|
108
117
|
try:
|
109
|
-
dfs =
|
118
|
+
dfs = read_excel_csv_data(read_excel_from_oss(oss), **kwargs)
|
110
119
|
result = {}
|
111
120
|
for sheet_name, df in dfs.items():
|
112
121
|
rows_list = df.values.tolist()
|
@@ -114,3 +123,17 @@ def read_excel_data_for_oss_write_to_dict(oss, **kwargs) -> dict:
|
|
114
123
|
return result
|
115
124
|
except Exception as e:
|
116
125
|
print(f"excel生成dict出错:{e}")
|
126
|
+
|
127
|
+
|
128
|
+
# 从 URL 中提取文件名
|
129
|
+
def get_file_suffix_name(url):
|
130
|
+
last_filename = ""
|
131
|
+
filename = url.split("/")[-1]
|
132
|
+
# 从文件名中提取文件后缀
|
133
|
+
if '.' in filename:
|
134
|
+
last_filename = '.' + filename.split('.')[-1].lower()
|
135
|
+
support_types = excel_extensions + csv_extensions
|
136
|
+
if last_filename in support_types:
|
137
|
+
return last_filename
|
138
|
+
else:
|
139
|
+
raise Exception(f"[{last_filename}] 该类型暂不支持!目前只支持 {support_types}")
|
smartpush/test.py
CHANGED
@@ -2,8 +2,18 @@
|
|
2
2
|
# @Time :2025/2/20 00:27
|
3
3
|
# @Author :luzebin
|
4
4
|
from smartpush.export.basic.ExcelExportChecker import check_excel_all
|
5
|
+
from smartpush.export.basic.ReadExcel import read_excel_from_oss
|
6
|
+
from smartpush.export.basic.ReadExcel import read_excel_and_write_to_dict
|
7
|
+
from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
|
5
8
|
|
6
9
|
if __name__ == '__main__':
|
7
10
|
oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/4d98418295524ab1b52340c2ed2afa4a/AutoTest-%E5%9B%BA%E5%AE%9AB-2025-02-14%20%E5%88%9B%E5%BB%BA%E7%9A%84Email33%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
8
|
-
oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/ddbe9965d83840199e678a66dc414518/%E8%90%A5%E9%94%80%E4%BB%BB%E5%8A%A1%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
9
|
-
print(check_excel_all(
|
11
|
+
# oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/ddbe9965d83840199e678a66dc414518/%E8%90%A5%E9%94%80%E4%BB%BB%E5%8A%A1%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
12
|
+
print(check_excel_all(oss1, oss1))
|
13
|
+
|
14
|
+
# expected_oss ="https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
15
|
+
# actual_oss = "https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
16
|
+
# #actual_oss= get_oss_address_with_retry("23161","https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx","",'{"page":1,"pageSize":10,"type":null,"status":null,"startTime":null,"endTime":null}')
|
17
|
+
# res=read_excel_and_write_to_dict(read_excel_from_oss(actual_oss))
|
18
|
+
# print(res)
|
19
|
+
# print(check_excel_all(actual_oss,expected_oss))
|
@@ -0,0 +1,14 @@
|
|
1
|
+
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
+
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
3
|
+
smartpush/test.py,sha256=m_Y67qrUeFphwM5jqBOTqheAufmnnjnBVF71nXRXUxg,1598
|
4
|
+
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
+
smartpush/export/basic/ExcelExportChecker.py,sha256=anvovO657rmo2PF8Mbn_BLFlhSOdyCut4yYoLFUK85c,10807
|
6
|
+
smartpush/export/basic/GetOssUrl.py,sha256=IYt-C-SBY4WU_y8dm9aH3uKj1d7M7sSNtitDrz4EfHU,4932
|
7
|
+
smartpush/export/basic/ReadExcel.py,sha256=rGPDq36ujLKA1dlz_33iQQU6I8dhlc5l2ij_JAQX2a0,5145
|
8
|
+
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
9
|
+
smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
|
10
|
+
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
smartpush-1.1.5.dist-info/METADATA,sha256=ffmLfAKhywIyo75R7Nfv5OcqSfyFnkfHrynL4DWYFTA,145
|
12
|
+
smartpush-1.1.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
13
|
+
smartpush-1.1.5.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
14
|
+
smartpush-1.1.5.dist-info/RECORD,,
|
smartpush-1.1.3.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
-
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
3
|
-
smartpush/test.py,sha256=VCemS6i05wjGmwo-hUXC83OTHbUL2KeEqoTfio6Rwqk,600
|
4
|
-
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
-
smartpush/export/basic/ExcelExportChecker.py,sha256=1tK103jGfofQUu_xABjgQL7abS5j8fGZ9Cn0O56ABis,9589
|
6
|
-
smartpush/export/basic/GetOssUrl.py,sha256=O2-HtcYzbabck9dKgLu8ga21_AiyDIzgdfoDgvqBY3c,1541
|
7
|
-
smartpush/export/basic/ReadExcel.py,sha256=kkMjA8p8IIludlSf6zyYnWX5AAG_x5DA1MvK5i1c2eg,4119
|
8
|
-
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
9
|
-
smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
|
10
|
-
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
smartpush-1.1.3.dist-info/METADATA,sha256=4r29z282fZPKB9dEWJiiX6aCRJwCTUvDtpqNT2Ur0QU,145
|
12
|
-
smartpush-1.1.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
13
|
-
smartpush-1.1.3.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
14
|
-
smartpush-1.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|