xmes-dingtalk-connectflow-sdk 1.0.0__tar.gz → 1.0.1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/PKG-INFO +2 -2
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/README.md +1 -1
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/pyproject.toml +1 -1
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/src/DingtalkConnectflowSDk/__init__.py +1 -1
- xmes_dingtalk_connectflow_sdk-1.0.1/src/DingtalkConnectflowSDk/_types.py +10 -0
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/src/DingtalkConnectflowSDk/complex_table.py +65 -2
- {xmes_dingtalk_connectflow_sdk-1.0.0 → xmes_dingtalk_connectflow_sdk-1.0.1}/LICENSE +0 -0
@@ -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
|
-
![Version](https://img.shields.io/badge/Version-v1.0.
|
19
|
+
![Version](https://img.shields.io/badge/Version-v1.0.1-green)
|
20
20
|
![Python Version](https://img.shields.io/badge/Python-%E2%89%A53.9-blue)
|
21
21
|
|
22
22
|
`xmes-dingtalk-connectflow-sdk` 是钉钉连接平台自建连接流SDK(向美而生),通过该工具可以方便快捷的调用钉钉的连接流。
|
@@ -1,5 +1,5 @@
|
|
1
1
|
## 概述
|
2
|
-
![Version](https://img.shields.io/badge/Version-v1.0.
|
2
|
+
![Version](https://img.shields.io/badge/Version-v1.0.1-green)
|
3
3
|
![Python Version](https://img.shields.io/badge/Python-%E2%89%A53.9-blue)
|
4
4
|
|
5
5
|
`xmes-dingtalk-connectflow-sdk` 是钉钉连接平台自建连接流SDK(向美而生),通过该工具可以方便快捷的调用钉钉的连接流。
|
@@ -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
|
"""
|
File without changes
|