xmes-dingtalk-connectflow-sdk 1.0.0__py3-none-any.whl → 1.0.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.
- DingtalkConnectflowSDk/__init__.py +1 -1
- DingtalkConnectflowSDk/_types.py +10 -0
- DingtalkConnectflowSDk/complex_table.py +65 -2
- {xmes_dingtalk_connectflow_sdk-1.0.0.dist-info → xmes_dingtalk_connectflow_sdk-1.0.1.dist-info}/METADATA +2 -2
- xmes_dingtalk_connectflow_sdk-1.0.1.dist-info/RECORD +7 -0
- xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/RECORD +0 -6
- {xmes_dingtalk_connectflow_sdk-1.0.0.dist-info → xmes_dingtalk_connectflow_sdk-1.0.1.dist-info}/LICENSE +0 -0
- {xmes_dingtalk_connectflow_sdk-1.0.0.dist-info → xmes_dingtalk_connectflow_sdk-1.0.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
from dataclasses import fields
|
2
|
+
|
3
|
+
|
4
|
+
class FilteredDataclass(type):
|
5
|
+
"""过滤kwargs中多余的键"""
|
6
|
+
|
7
|
+
def __call__(cls, *args, **kwargs):
|
8
|
+
valid_fields = {f.name for f in fields(cls)}
|
9
|
+
kwargs = {k: v for k, v in kwargs.items() if k in valid_fields}
|
10
|
+
return super().__call__(*args, **kwargs)
|
@@ -5,14 +5,20 @@ Author: LeslieLiang
|
|
5
5
|
Description: 多维表连接流SDK
|
6
6
|
"""
|
7
7
|
|
8
|
+
import json
|
9
|
+
from copy import deepcopy
|
8
10
|
from dataclasses import dataclass
|
9
11
|
from typing import Literal
|
10
12
|
|
11
13
|
from requests import post
|
12
14
|
|
15
|
+
from ._types import FilteredDataclass
|
16
|
+
|
13
17
|
|
14
18
|
@dataclass
|
15
19
|
class GetterFilter:
|
20
|
+
"""记录筛选器"""
|
21
|
+
|
16
22
|
field: str
|
17
23
|
operator: Literal[
|
18
24
|
'equal', 'notEqual', 'incontain', 'notContain', 'empty', 'notEmpty'
|
@@ -22,10 +28,63 @@ class GetterFilter:
|
|
22
28
|
|
23
29
|
@dataclass
|
24
30
|
class Updater:
|
31
|
+
"""记录更新器"""
|
32
|
+
|
25
33
|
record_id: str
|
26
34
|
fields: dict[str, any]
|
27
35
|
|
28
36
|
|
37
|
+
@dataclass
|
38
|
+
class GetterResult(metaclass=FilteredDataclass):
|
39
|
+
"""获取器结果"""
|
40
|
+
|
41
|
+
nextCursor: str = None
|
42
|
+
records: list[dict] = None
|
43
|
+
hasMore: bool = False
|
44
|
+
|
45
|
+
def __post_init__(self):
|
46
|
+
if self.records and isinstance(self.records, list):
|
47
|
+
self.records = self.__records_handle()
|
48
|
+
|
49
|
+
def __records_handle(self):
|
50
|
+
records: list[dict] = []
|
51
|
+
for record in self.records:
|
52
|
+
record_temp = {'id': record.get('id'), 'fields': {}}
|
53
|
+
fields: dict = record.get('fields')
|
54
|
+
|
55
|
+
for field_name, field_value in fields.items():
|
56
|
+
_value = deepcopy(field_value)
|
57
|
+
if isinstance(field_value, dict):
|
58
|
+
if 'link' in field_value:
|
59
|
+
_value = field_value.get('link')
|
60
|
+
elif 'name' in field_value:
|
61
|
+
_value = field_value.get('name')
|
62
|
+
|
63
|
+
record_temp['fields'][field_name] = _value
|
64
|
+
|
65
|
+
records.append(record_temp)
|
66
|
+
|
67
|
+
return records
|
68
|
+
|
69
|
+
def to_file(self, file_path: str):
|
70
|
+
"""
|
71
|
+
将数据写出到本地
|
72
|
+
|
73
|
+
Args:
|
74
|
+
file_path: 用于存储数据的文件路径, 不需要文件后缀
|
75
|
+
Returns:
|
76
|
+
数据文件路径
|
77
|
+
"""
|
78
|
+
|
79
|
+
if not self.records:
|
80
|
+
raise ValueError('数据记录为空, 无法写出')
|
81
|
+
|
82
|
+
with open(f'{file_path}.json', 'w', encoding='utf-8') as f:
|
83
|
+
f.write(json.dumps(self.records, ensure_ascii=False, indent=2))
|
84
|
+
|
85
|
+
return file_path
|
86
|
+
|
87
|
+
|
29
88
|
class Table:
|
30
89
|
__HEADERS = {
|
31
90
|
'Content-Type': 'application/json',
|
@@ -46,7 +105,7 @@ class Table:
|
|
46
105
|
cursor: str = '',
|
47
106
|
combination: Literal['and', 'or'] = 'and',
|
48
107
|
filters: list[GetterFilter] | None = None,
|
49
|
-
)
|
108
|
+
):
|
50
109
|
"""
|
51
110
|
获取表格数据
|
52
111
|
Args:
|
@@ -78,7 +137,11 @@ class Table:
|
|
78
137
|
reqdata['handle_get']['filter'] = filter_field
|
79
138
|
|
80
139
|
resp = post(self.flow_url, json=reqdata, headers=self.__HEADERS)
|
81
|
-
|
140
|
+
result: dict = resp.json().get('GET_RESULT')
|
141
|
+
|
142
|
+
getter_result = GetterResult(**result)
|
143
|
+
|
144
|
+
return getter_result
|
82
145
|
|
83
146
|
def add(self, records: list[dict]):
|
84
147
|
"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xmes-dingtalk-connectflow-sdk
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.1
|
4
4
|
Summary: DingTalk Connection Platform Connection Flow SDK
|
5
5
|
License: MIT
|
6
6
|
Author: leslieliang
|
@@ -16,7 +16,7 @@ Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
16
16
|
Description-Content-Type: text/markdown
|
17
17
|
|
18
18
|
## 概述
|
19
|
-

|
20
20
|

|
21
21
|
|
22
22
|
`xmes-dingtalk-connectflow-sdk` 是钉钉连接平台自建连接流SDK(向美而生),通过该工具可以方便快捷的调用钉钉的连接流。
|
@@ -0,0 +1,7 @@
|
|
1
|
+
DingtalkConnectflowSDk/__init__.py,sha256=-hU6zkU0j1fC1i5ctzX9dvrooD_4Z9mJqjvz13yiqPc,69
|
2
|
+
DingtalkConnectflowSDk/_types.py,sha256=TnJI3HHXVObasHWWdqBkX9n-N5E1IENmx7a4k0ehbdk,317
|
3
|
+
DingtalkConnectflowSDk/complex_table.py,sha256=V4Az32gtsMlbjshrumuO_7dsx67I3EwK6-mceeZAurk,7000
|
4
|
+
xmes_dingtalk_connectflow_sdk-1.0.1.dist-info/LICENSE,sha256=pLVhl_GNSUPILCWP8DLtqZXytsqXr1lfPp4RwXXypZc,1090
|
5
|
+
xmes_dingtalk_connectflow_sdk-1.0.1.dist-info/METADATA,sha256=dMVvQ_UqRGy_1WRpFxOiJcvIZpxUcezwig0dRH4YLGc,2000
|
6
|
+
xmes_dingtalk_connectflow_sdk-1.0.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
7
|
+
xmes_dingtalk_connectflow_sdk-1.0.1.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
DingtalkConnectflowSDk/__init__.py,sha256=s2BgEZj3tpumNOOqD46MPX5DwUB3NuZnh3BQ3Yqbbac,69
|
2
|
-
DingtalkConnectflowSDk/complex_table.py,sha256=CvqjGcx3OS8KO-tQH1uEOjw6wNCux_LTX7l5t8UjEKo,5203
|
3
|
-
xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/LICENSE,sha256=pLVhl_GNSUPILCWP8DLtqZXytsqXr1lfPp4RwXXypZc,1090
|
4
|
-
xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/METADATA,sha256=PPrsvGWsGdNg4X5OjLmlXxBeQoaFokmdPuyedBVNGl0,2000
|
5
|
-
xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
6
|
-
xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|