5
5
from UPDATE_FIELD import UPDATE_FIELD
6
6
7
7
def CONVERSION_FIELDS_HUMAN_TO_MACHINE (app_token = None , table_id = None , view_id = None , page_token = None , page_size = None , config_file = None ):
8
-
9
8
if config_file is None :
10
9
config_file = 'feishu-config.ini'
11
10
@@ -19,28 +18,32 @@ def CONVERSION_FIELDS_HUMAN_TO_MACHINE(app_token=None, table_id=None, view_id=No
19
18
if not table_id :
20
19
table_id = config .get ('ID' , 'table_id' )
21
20
22
-
23
- field_type = 1
21
+ field_type = 1
24
22
fields_map = dict (config .items ('FIELD_MAP' ))
25
23
26
24
# 获取当前的字段
27
- current_fields = LIST_FIELDS (app_token = app_token , table_id = table_id , view_id = view_id , page_token = page_token , page_size = page_size , config_file = config_file )
25
+ current_fields = LIST_FIELDS (app_token = app_token , table_id = table_id , view_id = view_id , page_token = page_token ,
26
+ page_size = page_size , config_file = config_file )
27
+
28
+ if 'data' in current_fields and isinstance (current_fields ['data' ], dict ):
29
+ for field in current_fields ['data' ]['items' ]:
30
+ # 检查当前字段是否在映射中
31
+ if field ['field_name' ] in fields_map :
32
+ field_id = field ['field_id' ] # 获取字段的ID
33
+ field_name = fields_map [field ['field_name' ]] # 获取字段的映射名称
34
+ # 如果在,则更新字段名
35
+ UPDATE_FIELD (app_token = app_token , table_id = table_id , field_id = field_id , field_name = field_name ,
36
+ field_type = field_type )
37
+
38
+ # 打印处理后的数据
39
+ print (f"Field '{ field ['field_name' ]} ' converted to '{ field_name } '" )
40
+ else :
41
+ # 当没有有效数据时的处理逻辑
42
+ print ("没有获取到有效的字段数据" )
28
43
29
- # 遍历当前的字段
30
- for field in current_fields ['data' ]['items' ]:
31
- # 检查当前字段是否在映射中
32
- if field ['field_name' ] in fields_map :
33
44
34
- field_id = field ['field_id' ] # 获取字段的ID
35
- field_name = fields_map [field ['field_name' ]] # 获取字段的映射名称
36
- # 如果在,则更新字段名
37
- UPDATE_FIELD (app_token = app_token , table_id = table_id , field_id = field_id , field_name = field_name , field_type = field_type )
38
45
39
- # 打印处理后的数据
40
- print (f"Field '{ field ['field_name' ]} ' converted to '{ field_name } '" )
41
-
42
-
43
- def CONVERSION_FIELDS_MACHINE_TO_HUMAN (app_token = None , table_id = None , view_id = None , page_token = None , page_size = None , config_file = None ):
46
+ def CONVERSION_FIELDS_MACHINE_TO_HUMAN_V1 (app_token = None , table_id = None , view_id = None , page_token = None , page_size = None , config_file = None ):
44
47
45
48
if config_file is None :
46
49
config_file = 'feishu-config.ini'
@@ -80,6 +83,49 @@ def CONVERSION_FIELDS_MACHINE_TO_HUMAN(app_token=None, table_id=None, view_id=No
80
83
print (f"Field '{ field ['field_name' ]} ' converted to '{ field_name } '" )
81
84
82
85
86
+
87
+ def CONVERSION_FIELDS_MACHINE_TO_HUMAN (app_token = None , table_id = None , view_id = None , page_token = None , page_size = None , config_file = None ):
88
+
89
+ if config_file is None :
90
+ config_file = 'feishu-config.ini'
91
+
92
+ # 读取配置文件
93
+ config = configparser .ConfigParser ()
94
+ config .read (config_file , encoding = 'utf-8' )
95
+
96
+ # 如果参数为空,则使用配置文件中的默认值
97
+ if not app_token :
98
+ app_token = config .get ('TOKEN' , 'app_token' )
99
+ if not table_id :
100
+ table_id = config .get ('ID' , 'table_id' )
101
+
102
+ fields_map = dict (config .items ('FIELD_MAP' ))
103
+
104
+ # 获取当前的字段
105
+ current_fields = LIST_FIELDS (app_token = app_token , table_id = table_id , view_id = view_id , page_token = page_token , page_size = page_size , config_file = config_file )
106
+
107
+ # 反转字典映射
108
+ reversed_fields_map = {v : k for k , v in fields_map .items ()}
109
+
110
+ field_type = 1
111
+
112
+ if 'data' in current_fields and isinstance (current_fields ['data' ], dict ):
113
+ for field in current_fields ['data' ]['items' ]:
114
+ # 检查当前字段是否在映射中
115
+ if field ['field_name' ] in reversed_fields_map :
116
+ # 如果在,则更新字段名
117
+ #UPDATE_FIELD(app_token=app_token, table_id=table_id, field_id=field['field_id'], field_name=reversed_fields_map[field['field_name']], field_type=1)
118
+ field_id = field ['field_id' ] # 获取字段的ID
119
+ field_name = reversed_fields_map [field ['field_name' ]] # 获取字段的映射名称
120
+ UPDATE_FIELD (app_token = app_token , table_id = table_id , field_id = field_id , field_name = field_name , field_type = field_type )
121
+ # 打印处理后的数据
122
+ print (f"Field '{ field ['field_name' ]} ' converted to '{ field_name } '" )
123
+ else :
124
+ # 当没有有效数据时的处理逻辑
125
+ print ("没有获取到有效的字段数据" )
126
+
127
+
128
+
83
129
def CONVERSION_FIELDS_CMD ():
84
130
85
131
parser = argparse .ArgumentParser (description = 'Human-to-Machine and Machine-to-Human Field Name Conversion' )
0 commit comments