xmes-dingtalk-connectflow-sdk 1.0.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- DingtalkConnectflowSDk/__init__.py +3 -0
- DingtalkConnectflowSDk/complex_table.py +193 -0
- xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/LICENSE +21 -0
- xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/METADATA +67 -0
- xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/RECORD +6 -0
- xmes_dingtalk_connectflow_sdk-1.0.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,193 @@
|
|
1
|
+
"""
|
2
|
+
Copyright (c) 2024-now LeslieLiang All rights reserved.
|
3
|
+
Build Date: 2024-12-18
|
4
|
+
Author: LeslieLiang
|
5
|
+
Description: 多维表连接流SDK
|
6
|
+
"""
|
7
|
+
|
8
|
+
from dataclasses import dataclass
|
9
|
+
from typing import Literal
|
10
|
+
|
11
|
+
from requests import post
|
12
|
+
|
13
|
+
|
14
|
+
@dataclass
|
15
|
+
class GetterFilter:
|
16
|
+
field: str
|
17
|
+
operator: Literal[
|
18
|
+
'equal', 'notEqual', 'incontain', 'notContain', 'empty', 'notEmpty'
|
19
|
+
]
|
20
|
+
value: list[str] = None
|
21
|
+
|
22
|
+
|
23
|
+
@dataclass
|
24
|
+
class Updater:
|
25
|
+
record_id: str
|
26
|
+
fields: dict[str, any]
|
27
|
+
|
28
|
+
|
29
|
+
class Table:
|
30
|
+
__HEADERS = {
|
31
|
+
'Content-Type': 'application/json',
|
32
|
+
}
|
33
|
+
|
34
|
+
def __init__(self, flow_url: str, did: str, tid: str):
|
35
|
+
self.flow_url = flow_url
|
36
|
+
self.did = did
|
37
|
+
self.tid = tid
|
38
|
+
self.global_reqdata = {
|
39
|
+
'did': did,
|
40
|
+
'tid': tid,
|
41
|
+
}
|
42
|
+
|
43
|
+
def get(
|
44
|
+
self,
|
45
|
+
size=20,
|
46
|
+
cursor: str = '',
|
47
|
+
combination: Literal['and', 'or'] = 'and',
|
48
|
+
filters: list[GetterFilter] | None = None,
|
49
|
+
) -> dict:
|
50
|
+
"""
|
51
|
+
获取表格数据
|
52
|
+
Args:
|
53
|
+
size: 每页数据条数, 默认为 20
|
54
|
+
cursor: 分页游标, 首次请求可不传, 后续需传入上一次返回的 nextCursor 值
|
55
|
+
combination: 组合方式
|
56
|
+
filters: 过滤条件
|
57
|
+
Returns:
|
58
|
+
表格数据
|
59
|
+
"""
|
60
|
+
|
61
|
+
reqdata = {
|
62
|
+
**self.global_reqdata,
|
63
|
+
'handle': 'GET',
|
64
|
+
'handle_get': {
|
65
|
+
'size': size,
|
66
|
+
'cursor': cursor,
|
67
|
+
},
|
68
|
+
}
|
69
|
+
|
70
|
+
if combination and combination in ['and', 'or']:
|
71
|
+
filter_field = {}
|
72
|
+
filter_field['combination'] = combination
|
73
|
+
if filters and isinstance(filters, list):
|
74
|
+
conditions = [
|
75
|
+
item.__dict__ for item in filters if isinstance(item, GetterFilter)
|
76
|
+
]
|
77
|
+
filter_field['conditions'] = conditions
|
78
|
+
reqdata['handle_get']['filter'] = filter_field
|
79
|
+
|
80
|
+
resp = post(self.flow_url, json=reqdata, headers=self.__HEADERS)
|
81
|
+
return resp.json().get('GET_RESULT')
|
82
|
+
|
83
|
+
def add(self, records: list[dict]):
|
84
|
+
"""
|
85
|
+
新增记录
|
86
|
+
Args:
|
87
|
+
records: 新增记录列表
|
88
|
+
Returns:
|
89
|
+
新增记录结果
|
90
|
+
"""
|
91
|
+
|
92
|
+
if not records or not isinstance(records, list):
|
93
|
+
raise ValueError('records must be a list')
|
94
|
+
|
95
|
+
records_clean = [
|
96
|
+
record for record in records if record and isinstance(record, dict)
|
97
|
+
]
|
98
|
+
if not records_clean:
|
99
|
+
raise ValueError('records must not be empty')
|
100
|
+
|
101
|
+
reqdata = {
|
102
|
+
**self.global_reqdata,
|
103
|
+
'handle': 'ADD',
|
104
|
+
'handle_add': {
|
105
|
+
'records': records_clean,
|
106
|
+
},
|
107
|
+
}
|
108
|
+
|
109
|
+
resp = post(self.flow_url, json=reqdata, headers=self.__HEADERS)
|
110
|
+
return resp.json().get('ADD_RESULT')
|
111
|
+
|
112
|
+
def update(self, records: list[Updater]):
|
113
|
+
"""
|
114
|
+
更新记录
|
115
|
+
Args:
|
116
|
+
records: 更新记录列表
|
117
|
+
Returns:
|
118
|
+
更新记录结果
|
119
|
+
"""
|
120
|
+
|
121
|
+
if not records or not isinstance(records, list):
|
122
|
+
raise ValueError('records must be a list')
|
123
|
+
|
124
|
+
records_clean = [
|
125
|
+
record.__dict__
|
126
|
+
for record in records
|
127
|
+
if record and isinstance(record, Updater)
|
128
|
+
]
|
129
|
+
if not records_clean:
|
130
|
+
raise ValueError('records must not be empty')
|
131
|
+
|
132
|
+
reqdata = {
|
133
|
+
**self.global_reqdata,
|
134
|
+
'handle': 'UPDATE',
|
135
|
+
'handle_update': {
|
136
|
+
'records': records_clean,
|
137
|
+
},
|
138
|
+
}
|
139
|
+
|
140
|
+
resp = post(self.flow_url, json=reqdata, headers=self.__HEADERS)
|
141
|
+
return resp.json().get('UPDATE_RESULT')
|
142
|
+
|
143
|
+
def delete(self, record_ids: list[str]):
|
144
|
+
"""
|
145
|
+
删除记录
|
146
|
+
Args:
|
147
|
+
record_ids: 记录 id 列表
|
148
|
+
Returns:
|
149
|
+
删除记录结果
|
150
|
+
"""
|
151
|
+
|
152
|
+
if not record_ids or not isinstance(record_ids, list):
|
153
|
+
raise ValueError('record_ids must be a list')
|
154
|
+
|
155
|
+
record_ids_clean = [
|
156
|
+
record_id
|
157
|
+
for record_id in record_ids
|
158
|
+
if record_id and isinstance(record_id, str)
|
159
|
+
]
|
160
|
+
|
161
|
+
reqdata = {
|
162
|
+
**self.global_reqdata,
|
163
|
+
'handle': 'DELETE',
|
164
|
+
'handle_delete': {
|
165
|
+
'record_ids': record_ids_clean,
|
166
|
+
},
|
167
|
+
}
|
168
|
+
|
169
|
+
resp = post(self.flow_url, json=reqdata, headers=self.__HEADERS)
|
170
|
+
return resp.json().get('DELETE_RESULT')
|
171
|
+
|
172
|
+
|
173
|
+
class ComplexTable:
|
174
|
+
def __init__(self, flow_url: str):
|
175
|
+
"""
|
176
|
+
初始化 ComplexTable 类
|
177
|
+
Args:
|
178
|
+
flow_url: 连接流 url
|
179
|
+
"""
|
180
|
+
|
181
|
+
self.flow_url = flow_url
|
182
|
+
|
183
|
+
def get_table(self, did: str, tid: str) -> Table:
|
184
|
+
"""
|
185
|
+
获取表格对象
|
186
|
+
Args:
|
187
|
+
did: 文档 id
|
188
|
+
tid: 数据表 id
|
189
|
+
Returns:
|
190
|
+
Table 对象
|
191
|
+
"""
|
192
|
+
|
193
|
+
return Table(self.flow_url, did, tid)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Martian Bugs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: xmes-dingtalk-connectflow-sdk
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: DingTalk Connection Platform Connection Flow SDK
|
5
|
+
License: MIT
|
6
|
+
Author: leslieliang
|
7
|
+
Author-email: zwliang98@163.com
|
8
|
+
Requires-Python: >=3.9
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
15
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
16
|
+
Description-Content-Type: text/markdown
|
17
|
+
|
18
|
+
## 概述
|
19
|
+
![Version](https://img.shields.io/badge/Version-v1.0.0-green)
|
20
|
+
![Python Version](https://img.shields.io/badge/Python-%E2%89%A53.9-blue)
|
21
|
+
|
22
|
+
`xmes-dingtalk-connectflow-sdk` 是钉钉连接平台自建连接流SDK(向美而生),通过该工具可以方便快捷的调用钉钉的连接流。
|
23
|
+
|
24
|
+
## 安装使用
|
25
|
+
```bash
|
26
|
+
pip install xmes-dingtalk-connectflow-sdk
|
27
|
+
```
|
28
|
+
|
29
|
+
## 功能特征
|
30
|
+
- 支持连接流 `多维表CURD_241217`
|
31
|
+
|
32
|
+
## 使用方法
|
33
|
+
### ComplexTable
|
34
|
+
该工具提供了连接流 `多维表CURD_241217` 的操作调用工具。
|
35
|
+
```python
|
36
|
+
from DingtalkConnectflowSDK import ComplexTable, GetterFilter, Updater
|
37
|
+
|
38
|
+
# 初始化ComplexTable对象
|
39
|
+
complextable = ComplexTable(flow_url='<连接流的同步协调URL>')
|
40
|
+
|
41
|
+
# 获取 Table 对象
|
42
|
+
table = complextable.get_table(did='<文档ID>', tid='<数据表ID>')
|
43
|
+
|
44
|
+
# 查询数据
|
45
|
+
filters = [
|
46
|
+
GetterFilter(field='来源', operator='equal', value=['SDK', 'API'])
|
47
|
+
]
|
48
|
+
resp = table.get(size=10, fillters=filters)
|
49
|
+
|
50
|
+
# 新增数据
|
51
|
+
records = [
|
52
|
+
{'标题': 'Test Record 1', '来源': 'SDK},
|
53
|
+
{'标题': 'Test Record 2', '来源': 'SDK},
|
54
|
+
]
|
55
|
+
resp = table.add(records)
|
56
|
+
|
57
|
+
# 更新数据
|
58
|
+
records = [
|
59
|
+
Updater(record_id='<记录ID>', fields={'来源': 'API'}),
|
60
|
+
Updater(record_id='<记录ID>', fields={'来源': 'API'}),
|
61
|
+
]
|
62
|
+
resp = table.update(records)
|
63
|
+
|
64
|
+
# 删除数据
|
65
|
+
record_ids = ['<记录ID>', '<记录ID>']
|
66
|
+
resp = table.delete(record_ids)
|
67
|
+
```
|
@@ -0,0 +1,6 @@
|
|
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,,
|