smartpush 1.2.7__py3-none-any.whl → 1.2.8__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 +33 -0
- smartpush/export/basic/ReadExcel.py +2 -1
- smartpush/test.py +14 -11
- smartpush/utils/DataTypeUtils.py +30 -0
- {smartpush-1.2.7.dist-info → smartpush-1.2.8.dist-info}/METADATA +1 -1
- smartpush-1.2.8.dist-info/RECORD +15 -0
- {smartpush-1.2.7.dist-info → smartpush-1.2.8.dist-info}/WHEEL +1 -1
- smartpush-1.2.7.dist-info/RECORD +0 -14
- {smartpush-1.2.7.dist-info → smartpush-1.2.8.dist-info}/top_level.txt +0 -0
@@ -2,6 +2,7 @@ import copy
|
|
2
2
|
import json
|
3
3
|
from urllib.parse import unquote
|
4
4
|
from smartpush.export.basic.ReadExcel import *
|
5
|
+
from smartpush.utils import DataTypeUtils
|
5
6
|
|
6
7
|
"""
|
7
8
|
用于excel校验
|
@@ -326,3 +327,35 @@ def compare_lists(actual_dict_list, expected_dict_list):
|
|
326
327
|
if item1 != item2:
|
327
328
|
diff.append(('列表索引的不同值', i, (item1, item2)))
|
328
329
|
return diff
|
330
|
+
|
331
|
+
|
332
|
+
def check_field_format(actual_oss, **kwargs):
|
333
|
+
"""
|
334
|
+
逐个校验字段类型
|
335
|
+
**kwargs: fileds为需检查字段,结构为dict,如{"0": {"1": "email", "2": "time"}},
|
336
|
+
即校验第一个sheet第二个字段需符合email格式,第二个字段需符合time格式
|
337
|
+
"""
|
338
|
+
# 获取oss内容并存入dict
|
339
|
+
actual = read_excel_from_oss(actual_oss)
|
340
|
+
actual_data_copy = copy.deepcopy(actual)
|
341
|
+
actual_dict = read_excel_and_write_to_dict(actual, **kwargs)
|
342
|
+
# 解析参数并校验字段类型
|
343
|
+
errors = []
|
344
|
+
actual_dict_key = list(actual_dict.keys())
|
345
|
+
for key in kwargs["fileds"].keys():
|
346
|
+
if isinstance(key, int) and 0 <= key < len(actual_dict):
|
347
|
+
for filed_key in kwargs["fileds"][key].keys():
|
348
|
+
num = 1
|
349
|
+
for row in actual_dict[actual_dict_key[key]]:
|
350
|
+
if kwargs["fileds"][key][filed_key] == "email":
|
351
|
+
fool = DataTypeUtils.DataTypeUtils().check_email_format(email=row[filed_key])
|
352
|
+
if not fool:
|
353
|
+
errors.append(f"{actual_dict_key[key]} 表, 第{num}行{filed_key}列{kwargs['fileds'][key][filed_key]}格式不符合规范, 值为:{row[filed_key]}")
|
354
|
+
elif kwargs["fileds"][key][filed_key] == "time":
|
355
|
+
fool = DataTypeUtils.DataTypeUtils().check_time_format(time_str=row[filed_key], precision=kwargs.get('precision', 's'))
|
356
|
+
if not fool:
|
357
|
+
errors.append(
|
358
|
+
f"{actual_dict_key[key]} 表, 第{num}行{filed_key}列{kwargs['fileds'][key][filed_key]}格式不符合规范, 值为:{row[filed_key]}")
|
359
|
+
num += 1
|
360
|
+
print(errors)
|
361
|
+
return False if len(errors) > 0 else True
|
@@ -95,7 +95,8 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
|
95
95
|
row_dict = {} # 创建一个空字典来存储按行转换的数据
|
96
96
|
for sheet_name, row in dfs.items():
|
97
97
|
row = row.to_dict(orient='records')
|
98
|
-
if kwargs.get("ignore_sort") is not None
|
98
|
+
if kwargs.get("ignore_sort") is not None and StringUtils.to_lower(sheet_name) == \
|
99
|
+
StringUtils.to_lower(kwargs.get("ignore_sort_sheet_name", sheet_name)): # 可传参指定那个sheet_name
|
99
100
|
sorted_data_asc = sorted(row[1:], key=lambda x: x.get(kwargs.get("ignore_sort"), 0),
|
100
101
|
reverse=True) # 内部排序
|
101
102
|
sorted_data_asc = [row[0]] + sorted_data_asc
|
smartpush/test.py
CHANGED
@@ -3,23 +3,23 @@
|
|
3
3
|
# @Author :luzebin
|
4
4
|
import pandas as pd
|
5
5
|
|
6
|
-
from smartpush.export.basic
|
7
|
-
read_excel_from_oss, read_excel_csv_data, check_excel
|
6
|
+
from smartpush.export.basic import ExcelExportChecker
|
8
7
|
from smartpush.export.basic.ReadExcel import read_excel_from_oss
|
9
8
|
from smartpush.export.basic.ReadExcel import read_excel_and_write_to_dict
|
10
9
|
from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
|
10
|
+
from smartpush.utils.DataTypeUtils import DataTypeUtils
|
11
11
|
|
12
12
|
if __name__ == '__main__':
|
13
|
-
oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-
|
14
|
-
oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-
|
13
|
+
oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/31c1a577af244c65ab9f9a984c64f3d9/ab%E5%BC%B9%E7%AA%97%E6%B5%8B%E8%AF%952.10%E5%88%9B%E5%BB%BA-%E6%9C%89%E5%85%A8%E9%83%A8%E6%95%B0%E6%8D%AE%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx"
|
14
|
+
oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/31c1a577af244c65ab9f9a984c64f3d9/ab%E5%BC%B9%E7%AA%97%E6%B5%8B%E8%AF%952.10%E5%88%9B%E5%BB%BA-%E6%9C%89%E5%85%A8%E9%83%A8%E6%95%B0%E6%8D%AE%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx"
|
15
15
|
# # print(check_excel_all(oss1, oss1))
|
16
|
-
oss3 = "https://cdn.smartpushedm.com/material_ec2/2025-02-
|
17
|
-
oss4 = "https://cdn.smartpushedm.com/material_ec2/2025-02-
|
16
|
+
oss3 = "https://cdn.smartpushedm.com/material_ec2/2025-02-27/a5e18e3b3a83432daca871953cb8471b/【自动化导出】营销活动URL点击与热图.xlsx"
|
17
|
+
oss4 = "https://cdn.smartpushedm.com/material_ec2/2025-02-25/58c4a3a885884741b22380c360ac2894/【自动化导出】营销活动URL点击与热图.xlsx"
|
18
18
|
expected_oss = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/757df7e77ce544e193257c0da35a4983/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
19
|
-
actual_oss = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/757df7e77ce544e193257c0da35a4983/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
19
|
+
# actual_oss = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/757df7e77ce544e193257c0da35a4983/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
20
20
|
|
21
|
-
e_person_oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-27/b48f34b3e88045d189631ec1f0f23d51/%E5%AF%BC%E5%87%BA%E5%85%A8%E9%83%A8%E5%AE%A2%E6%88%B7.csv"
|
22
|
-
a_person_oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-27/c50519d803c04e3b9b52d9f625fed413/%E5%AF%BC%E5%87%BA%E5%85%A8%E9%83%A8%E5%AE%A2%E6%88%B7.csv"
|
21
|
+
# e_person_oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-27/b48f34b3e88045d189631ec1f0f23d51/%E5%AF%BC%E5%87%BA%E5%85%A8%E9%83%A8%E5%AE%A2%E6%88%B7.csv"
|
22
|
+
# a_person_oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-27/c50519d803c04e3b9b52d9f625fed413/%E5%AF%BC%E5%87%BA%E5%85%A8%E9%83%A8%E5%AE%A2%E6%88%B7.csv"
|
23
23
|
|
24
24
|
# # #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}')
|
25
25
|
# # res=read_excel_and_write_to_dict(read_excel_from_oss(actual_oss))
|
@@ -27,7 +27,10 @@ if __name__ == '__main__':
|
|
27
27
|
# # print(read_excel_and_write_to_dict(read_excel_from_oss(oss1), type=".xlsx"))
|
28
28
|
# print(check_excel(check_type="all", actual_oss=actual_oss, expected_oss=expected_oss))
|
29
29
|
# print(check_excel_all(actual_oss=oss1, expected_oss=oss2,skiprows =1))
|
30
|
-
print(check_excel_all(actual_oss=oss1, expected_oss=oss2,
|
30
|
+
# print(check_excel_all(actual_oss=oss1, expected_oss=oss2,ignore_sort=True))
|
31
31
|
# print(check_excel_all(actual_oss=a_person_oss2, expected_oss=e_person_oss1, check_type="including"))
|
32
|
-
# print(check_excel_all(actual_oss=
|
32
|
+
# print(check_excel_all(actual_oss=oss1, expected_oss=oss2, ignore_sort=True))
|
33
33
|
# read_excel_csv_data(type=)
|
34
|
+
# print(DataTypeUtils().check_email_format())
|
35
|
+
errors = ExcelExportChecker.check_field_format(actual_oss=oss1, fileds={0: {2: "email", 5: "time"}}, skiprows=2)
|
36
|
+
print(errors)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import re
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
|
5
|
+
class DataTypeUtils:
|
6
|
+
|
7
|
+
def check_email_format(self, email):
|
8
|
+
# 检查邮箱是否符合格式
|
9
|
+
if email != "" or email is not None:
|
10
|
+
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
11
|
+
return bool(re.match(pattern, email))
|
12
|
+
|
13
|
+
def check_time_format(self, time_str, precision="s"):
|
14
|
+
# 检查时间是否符合格式,并校验是精确到秒还是分
|
15
|
+
if precision == 's':
|
16
|
+
try:
|
17
|
+
# 尝试按照精确到秒的格式解析
|
18
|
+
datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S')
|
19
|
+
return True
|
20
|
+
except ValueError:
|
21
|
+
return False
|
22
|
+
elif precision == 'm':
|
23
|
+
try:
|
24
|
+
# 尝试按照精确到分钟的格式解析
|
25
|
+
datetime.strptime(time_str, '%Y-%m-%d %H:%M')
|
26
|
+
return True
|
27
|
+
except ValueError:
|
28
|
+
return False
|
29
|
+
else:
|
30
|
+
raise ValueError("Invalid precision parameter. Use 's' for seconds or 'm' for minutes.")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
+
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
3
|
+
smartpush/test.py,sha256=JpjJe4F7MEmmbjgPI2xCW4HkE9MZRd44xYVKoLSxxRA,3315
|
4
|
+
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
+
smartpush/export/basic/ExcelExportChecker.py,sha256=igJH-RQZWUU5wGVPzoklWxSYpjQRoUFChq1-A-De0nQ,16386
|
6
|
+
smartpush/export/basic/GetOssUrl.py,sha256=zlExF_jy_TRV5lp0fws8Wed5MF_byp7JAEmvARVqlIg,3263
|
7
|
+
smartpush/export/basic/ReadExcel.py,sha256=ZnG2mtYqLY-xuYx9SyulbdYUP_0E5jIeKDewfakAsTw,7342
|
8
|
+
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
9
|
+
smartpush/utils/DataTypeUtils.py,sha256=BC7ioztO3vAfKd1EOoNvXdVuXYY8qjNskV1DP7LhW-M,1082
|
10
|
+
smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
|
11
|
+
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
+
smartpush-1.2.8.dist-info/METADATA,sha256=SyedtaWkHLFDo9aoke_TJUG4lESSzjq0YzZoeNlryGY,145
|
13
|
+
smartpush-1.2.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
14
|
+
smartpush-1.2.8.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
15
|
+
smartpush-1.2.8.dist-info/RECORD,,
|
smartpush-1.2.7.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=ByqTF3rwjS5fHFhT_o5PGo-5WIzytxfIhIA7Cpih-eU,3052
|
4
|
-
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
-
smartpush/export/basic/ExcelExportChecker.py,sha256=BsThRl0rGlGxNQZP8rzgqCwlkdFu7JM5lMy7ypE-kFs,14553
|
6
|
-
smartpush/export/basic/GetOssUrl.py,sha256=zlExF_jy_TRV5lp0fws8Wed5MF_byp7JAEmvARVqlIg,3263
|
7
|
-
smartpush/export/basic/ReadExcel.py,sha256=SkEw4773f8pAFH6K4kM120NJI2dFTZRDYuA_EY-Pan4,7170
|
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.2.7.dist-info/METADATA,sha256=N9_NqcRES80PuyMHicleAkszj6xkvxBxuGWHDgd5BqE,145
|
12
|
-
smartpush-1.2.7.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
13
|
-
smartpush-1.2.7.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
14
|
-
smartpush-1.2.7.dist-info/RECORD,,
|
File without changes
|