smartpush 1.5.3__py3-none-any.whl → 1.5.4__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/base/request_base.py +42 -5
- smartpush/base/url_enum.py +1 -1
- smartpush/form/form_after.py +19 -28
- smartpush/form/test_form_after.py +2 -0
- {smartpush-1.5.3.dist-info → smartpush-1.5.4.dist-info}/METADATA +1 -1
- {smartpush-1.5.3.dist-info → smartpush-1.5.4.dist-info}/RECORD +8 -7
- {smartpush-1.5.3.dist-info → smartpush-1.5.4.dist-info}/WHEEL +0 -0
- {smartpush-1.5.3.dist-info → smartpush-1.5.4.dist-info}/top_level.txt +0 -0
smartpush/base/request_base.py
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
import json
|
2
|
+
|
1
3
|
import requests
|
4
|
+
from requests import session
|
5
|
+
from requests.adapters import HTTPAdapter
|
6
|
+
from tenacity import stop_after_attempt, wait_fixed, retry
|
7
|
+
from urllib3 import Retry
|
8
|
+
|
9
|
+
from smartpush.export.basic.GetOssUrl import log_attempt
|
2
10
|
|
3
11
|
|
4
12
|
class RequestBase:
|
5
|
-
def __init__(self, host, headers):
|
13
|
+
def __init__(self, host, headers, retries=3, **kwargs):
|
6
14
|
"""
|
7
15
|
|
8
16
|
:param headers: 头,cookie
|
@@ -10,13 +18,42 @@ class RequestBase:
|
|
10
18
|
"""
|
11
19
|
self.host = host
|
12
20
|
self.headers = headers
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
|
22
|
+
# 配置重试策略
|
23
|
+
retry_strategy = Retry(
|
24
|
+
total=retries,
|
25
|
+
status_forcelist=[429, 500, 502, 503, 504],
|
26
|
+
backoff_factor=1
|
27
|
+
)
|
28
|
+
|
29
|
+
# 创建 Session 并配置适配器
|
30
|
+
self.session = requests.Session()
|
31
|
+
self.session.mount("https://", HTTPAdapter(max_retries=retry_strategy))
|
32
|
+
|
33
|
+
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
34
|
+
def request(self, method, path, **kwargs):
|
35
|
+
url = f"{self.host}{path}"
|
36
|
+
print(f"{method} 请求:", url)
|
37
|
+
# 统一处理请求参数
|
38
|
+
default_kwargs = {
|
39
|
+
"timeout": 30,
|
40
|
+
"headers": self.headers
|
41
|
+
}
|
42
|
+
default_kwargs.update(kwargs)
|
43
|
+
if default_kwargs.get('data'): # 如果data有值json序列化
|
44
|
+
data = json.dumps(default_kwargs.get('data'))
|
45
|
+
default_kwargs.update({'data': data})
|
46
|
+
try:
|
47
|
+
response = self.session.request(method, url, **default_kwargs)
|
48
|
+
response.raise_for_status()
|
49
|
+
print("响应内容为:\n", response.json())
|
50
|
+
return response.json()
|
51
|
+
except requests.exceptions.RequestException as e:
|
52
|
+
print(f"请求失败: {e}")
|
53
|
+
return None
|
16
54
|
|
17
55
|
|
18
56
|
class FormRequestBase(RequestBase):
|
19
57
|
def __init__(self, form_id, host, headers):
|
20
58
|
super().__init__(host, headers)
|
21
59
|
self.form_id = form_id
|
22
|
-
|
smartpush/base/url_enum.py
CHANGED
smartpush/form/form_after.py
CHANGED
@@ -6,10 +6,9 @@ from smartpush.export.basic.GetOssUrl import log_attempt
|
|
6
6
|
|
7
7
|
|
8
8
|
class FormAfter(FormRequestBase):
|
9
|
-
def __init__(self, form_id,
|
10
|
-
super().__init__(form_id,
|
9
|
+
def __init__(self, form_id, host, headers):
|
10
|
+
super().__init__(form_id, host, headers)
|
11
11
|
|
12
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
13
12
|
def callPageFormReportDetail(self, reportDetailType, start_time=None, end_time=None):
|
14
13
|
"""
|
15
14
|
获取PageFormReportDetail数据
|
@@ -22,28 +21,26 @@ class FormAfter(FormRequestBase):
|
|
22
21
|
if start_time is not None and end_time is not None:
|
23
22
|
requestParam["startTime"] = start_time
|
24
23
|
requestParam["endTime"] = end_time
|
25
|
-
result = self.
|
26
|
-
|
24
|
+
result = self.request(method=URL.pageFormReportDetail.method, path=URL.pageFormReportDetail.url,
|
25
|
+
data=requestParam)
|
27
26
|
persons_list = result["resultData"]["reportDetailData"]["datas"]
|
28
27
|
return persons_list
|
29
28
|
|
30
|
-
|
29
|
+
|
31
30
|
def callGetFormReportDetail(self):
|
32
31
|
requestParam = {"formId": self.form_id}
|
33
|
-
result = self.
|
34
|
-
|
32
|
+
result = self.request(method=URL.getFormReportDetail.method, path=URL.getFormReportDetail.url,
|
33
|
+
data=requestParam)
|
35
34
|
resultData = result["resultData"]
|
36
35
|
return resultData
|
37
36
|
|
38
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
39
37
|
def callGetFormPerformanceTrend(self):
|
40
38
|
requestParam = {"formId": self.form_id}
|
41
|
-
result = self.
|
42
|
-
|
39
|
+
result = self.request(method=URL.getFormPerformanceTrend.method, path=URL.getFormPerformanceTrend.url,
|
40
|
+
data=requestParam)
|
43
41
|
resultData = result["resultData"]
|
44
42
|
return resultData
|
45
43
|
|
46
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
47
44
|
def callEditCrowdPackage(self, _id=None, groupRules=None, groupRelation="$AND"):
|
48
45
|
"""
|
49
46
|
更新群组条件id
|
@@ -54,8 +51,7 @@ class FormAfter(FormRequestBase):
|
|
54
51
|
"""
|
55
52
|
requestParam = {"id": _id, "crowdName": "表单查询群组-自动化", "groupRelation": groupRelation,
|
56
53
|
"groupRules": groupRules, "triggerStock": False}
|
57
|
-
result = self.
|
58
|
-
result.raise_for_status()
|
54
|
+
result = self.request(method=URL.editCrowdPackage.method, path=URL.editCrowdPackage.url, data=requestParam)
|
59
55
|
assert result.get("code") == 1
|
60
56
|
resultData = result["resultData"]
|
61
57
|
assert resultData.get("status") == 2
|
@@ -65,30 +61,25 @@ class FormAfter(FormRequestBase):
|
|
65
61
|
requestParam = {"id": _id, "page": page, "pageSize": pageSize}
|
66
62
|
if filter_value is not None:
|
67
63
|
requestParam["filter"] = {filter_type: {"in": filter_value}}
|
68
|
-
result = self.
|
64
|
+
result = self.request(method=URL.crowdPersonList.method, path=URL.crowdPersonList.url, data=requestParam)
|
69
65
|
result.raise_for_status()
|
70
66
|
return result['resultData']
|
71
67
|
|
72
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
73
68
|
def callGetFormList(self, formName):
|
74
|
-
|
75
|
-
result = self.
|
76
|
-
result.raise_for_status()
|
69
|
+
requestParam = {'page': 1, 'pageSize': 10, 'name': formName}
|
70
|
+
result = self.request(method=URL.getFormList.method, path=URL.getFormList.url, data=requestParam)
|
77
71
|
return result["resultData"]['datas']
|
78
72
|
|
79
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
80
73
|
def callGetFormInfo(self):
|
81
|
-
|
82
|
-
result = self.
|
83
|
-
result.raise_for_status()
|
74
|
+
requestParam = {'formId': self.form_id}
|
75
|
+
result = self.request(method=URL.getFormInfo.method, path=URL.getFormInfo.url, params=requestParam)
|
84
76
|
return result['resultData']
|
85
77
|
|
86
|
-
@retry(stop=stop_after_attempt(3), wait=wait_fixed(2), after=log_attempt)
|
87
78
|
def callDeleteForm(self, merchant_id):
|
88
|
-
|
89
|
-
result = self.
|
90
|
-
result
|
91
|
-
print(f"删除id{self.form_id}表单成功")
|
79
|
+
requestParam = {"formId": self.form_id, "merchant_id": merchant_id}
|
80
|
+
result = self.request(url=self.host + URL.deleteForm.url, params=requestParam)
|
81
|
+
assert result['code']
|
82
|
+
print(f"删除id:{self.form_id}表单成功")
|
92
83
|
|
93
84
|
# -------- 处理数据 --------------
|
94
85
|
def collectFormDetails(self, key, start_time=None, end_time=None):
|
@@ -2,8 +2,8 @@ smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
|
2
2
|
smartpush/get_jira_info.py,sha256=OYaDV6VPAmkGKYLlRnsi1ZyKHU8xEiVnjsYrc41ZR0U,17910
|
3
3
|
smartpush/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
smartpush/base/faker_data.py,sha256=TOd5EKVImxZpsKEW_dtKa2iqiUGqU7OBkOM8pvqKVUc,24643
|
5
|
-
smartpush/base/request_base.py,sha256=
|
6
|
-
smartpush/base/url_enum.py,sha256=
|
5
|
+
smartpush/base/request_base.py,sha256=LQfbECJTIk57iV-JFNjOx_zWbhwCLWAWTOUU1VmwTIw,1877
|
6
|
+
smartpush/base/url_enum.py,sha256=_RcBMjDMWS_KOAK9T0HKG9msOWZLJGiKYKC4W5lOKjU,965
|
7
7
|
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
8
8
|
smartpush/export/basic/ExcelExportChecker.py,sha256=3IAeu1kjFS4MpDxjVB1htAcRA1BtfpH3xEkZyP4htAA,19963
|
9
9
|
smartpush/export/basic/GetOssUrl.py,sha256=LeF1y1_uJaYXth1KvO6mEDS29ezb9tliBv5SrbqYkXc,6136
|
@@ -12,17 +12,18 @@ smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0F
|
|
12
12
|
smartpush/flow/MockFlow.py,sha256=MI8WIMZyKlxrV5QVs8rXX6iD07Ldl37_L5Yb5FWqHzU,8595
|
13
13
|
smartpush/flow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
smartpush/form/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
smartpush/form/form_after.py,sha256=
|
15
|
+
smartpush/form/form_after.py,sha256=3z3dO22_ncVsAA1w9zGAcfJZCOELZ2lVBmaV-RfD0Hc,6335
|
16
16
|
smartpush/form/form_assert.py,sha256=wPIRfQHhr7lN1fFd-mp0z_qKMtF4jfrNxRWvp2xfqCg,257
|
17
17
|
smartpush/form/form_before.py,sha256=CCvAC_2yWPlnQGtjEA8LPLy9853Nq3nNjcL2GewFWIs,175
|
18
18
|
smartpush/form/form_client_operation.py,sha256=gg-5uHXCyMa_ypBSYPYFVxXdwZdYBJsNtUCqayknMBw,303
|
19
|
+
smartpush/form/test_form_after.py,sha256=aZglf2k2BUqKgL7FDMGX25rQ_ulj5kCd4R70hQzx4zs,58
|
19
20
|
smartpush/utils/DataTypeUtils.py,sha256=BC7ioztO3vAfKd1EOoNvXdVuXYY8qjNskV1DP7LhW-M,1082
|
20
21
|
smartpush/utils/EmailUtlis.py,sha256=DAHd73bJ8hiJCLEXtD0xcwxPD7SOPSmBB7Jvlf6gN6s,11201
|
21
22
|
smartpush/utils/ListDictUtils.py,sha256=Fm5_d7UyY6xB8gySMPdl5jIFSRhXZcYXdYW-_L1alcE,1640
|
22
23
|
smartpush/utils/StringUtils.py,sha256=n8mo9k0JQN63MReImgv-66JxmmymOGknR8pH2fkQrAo,4139
|
23
24
|
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
25
|
smartpush/utils/form_utils.py,sha256=ld-g_Dm_ZlnagQt7imYfUc87bcBRVlTctywuLtzmjXQ,849
|
25
|
-
smartpush-1.5.
|
26
|
-
smartpush-1.5.
|
27
|
-
smartpush-1.5.
|
28
|
-
smartpush-1.5.
|
26
|
+
smartpush-1.5.4.dist-info/METADATA,sha256=UWktqTBpOYyes2pWSBCBjNF_RsRAvSNqLLgkuDS3cdE,131
|
27
|
+
smartpush-1.5.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
28
|
+
smartpush-1.5.4.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
29
|
+
smartpush-1.5.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|