itam-assistant 0.1.1__py3-none-any.whl → 0.1.3__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.
- it_assistant/do_ai.py +443 -76
- it_assistant/intent_detail.py +4 -3
- it_assistant/openapi.py +270 -42
- itam_assistant-0.1.3.dist-info/METADATA +16 -0
- itam_assistant-0.1.3.dist-info/RECORD +19 -0
- {itam_assistant-0.1.1.dist-info → itam_assistant-0.1.3.dist-info}/WHEEL +1 -1
- main/__init__.py +0 -0
- main/ailyapp_client.py +132 -0
- main/do_ai.py +177 -0
- main/intent_detail.py +326 -0
- main/lark_client.py +159 -0
- main/logger.py +53 -0
- itam_assistant-0.1.1.dist-info/METADATA +0 -25
- itam_assistant-0.1.1.dist-info/RECORD +0 -13
- {itam_assistant-0.1.1.dist-info → itam_assistant-0.1.3.dist-info}/top_level.txt +0 -0
main/lark_client.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import lark_oapi as lark
|
|
4
|
+
from lark_oapi.api.sheets.v3 import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# SDK 使用说明: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/server-side-sdk/python--sdk/preparations-before-development
|
|
8
|
+
# 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用
|
|
9
|
+
|
|
10
|
+
class LarkdocsClient:
|
|
11
|
+
def __init__(self):
|
|
12
|
+
"""
|
|
13
|
+
初始化 Client 实例,tenant_access_token 会在 Client 初始化时自动获取
|
|
14
|
+
https://github.com/larksuite/oapi-sdk-python
|
|
15
|
+
"""
|
|
16
|
+
self.app_id = "cli_a48be9fd54a5900d"
|
|
17
|
+
self.app_secret = "pfiNeWKbkfbRvUunX3TrKdCCnftlUbxl"
|
|
18
|
+
# 创建 Lark 客户端
|
|
19
|
+
self.lark_client = lark.Client.builder().app_id(self.app_id).app_secret(self.app_secret).build()
|
|
20
|
+
|
|
21
|
+
def get_the_worksheet(self, spreadsheet_token):
|
|
22
|
+
|
|
23
|
+
# 获取工作表
|
|
24
|
+
# 创建client
|
|
25
|
+
# 使用 user_access_token 需开启 token 配置, 并在 request_option 中配置 token
|
|
26
|
+
# 构造请求对象
|
|
27
|
+
try:
|
|
28
|
+
request: QuerySpreadsheetSheetRequest = QuerySpreadsheetSheetRequest.builder() \
|
|
29
|
+
.spreadsheet_token(spreadsheet_token) \
|
|
30
|
+
.build()
|
|
31
|
+
|
|
32
|
+
# 发起请求
|
|
33
|
+
# option = self.lark_client.RequestOption.builder().user_access_token(
|
|
34
|
+
# "u-hQ.Vthwt5blbznh92YFKhflkkfsAl5R3hW20l5cy07ag").build()
|
|
35
|
+
response: QuerySpreadsheetSheetResponse = self.lark_client.sheets.v3.spreadsheet_sheet.query(request)
|
|
36
|
+
|
|
37
|
+
# 处理失败返回
|
|
38
|
+
if not response.success():
|
|
39
|
+
lark.logger.error(
|
|
40
|
+
f"client.sheets.v3.spreadsheet_sheet.query failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
41
|
+
return
|
|
42
|
+
return response.data
|
|
43
|
+
# 处理业务结果
|
|
44
|
+
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
45
|
+
except Exception as e:
|
|
46
|
+
lark.logger.error(f"[lark]get user id by email failed, err: {e}")
|
|
47
|
+
return None, e
|
|
48
|
+
|
|
49
|
+
def get_plaintextcontent(self, ranges, spreadsheet_token, sheet_id):
|
|
50
|
+
# 创建client
|
|
51
|
+
# 使用 user_access_token 需开启 token 配置, 并在 request_option 中配置 token
|
|
52
|
+
# 构造请求对象
|
|
53
|
+
# 构造请求对象
|
|
54
|
+
# json_str = "{\"ranges\":[\"459f7e!A1:A1\"]}"
|
|
55
|
+
body = ranges
|
|
56
|
+
request: lark.BaseRequest = lark.BaseRequest.builder() \
|
|
57
|
+
.http_method(lark.HttpMethod.POST) \
|
|
58
|
+
.uri(f"/open-apis/sheets/v3/spreadsheets/{spreadsheet_token}/sheets/{str(sheet_id)}/values/batch_get_plain") \
|
|
59
|
+
.token_types({lark.AccessTokenType.TENANT}) \
|
|
60
|
+
.body(body) \
|
|
61
|
+
.build()
|
|
62
|
+
|
|
63
|
+
# 发起请求
|
|
64
|
+
response: lark.BaseResponse = self.lark_client.request(request)
|
|
65
|
+
|
|
66
|
+
# 处理失败返回
|
|
67
|
+
if not response.success():
|
|
68
|
+
lark.logger.error(
|
|
69
|
+
f"client.request failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
# 处理业务结果
|
|
73
|
+
lark.logger.info(str(response.raw.content, lark.UTF_8))
|
|
74
|
+
return str(response.raw.content, lark.UTF_8)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def createsheets(self, spreadsheet_token, title):
|
|
78
|
+
# 创建工作表
|
|
79
|
+
# json_str = "{\"index\":0,\"title\":\"abc\"}"
|
|
80
|
+
# 构造请求对象
|
|
81
|
+
body = title
|
|
82
|
+
request: lark.BaseRequest = lark.BaseRequest.builder() \
|
|
83
|
+
.http_method(lark.HttpMethod.POST) \
|
|
84
|
+
.uri(f"/open-apis/sheets/v3/spreadsheets/{spreadsheet_token}/sheets") \
|
|
85
|
+
.token_types({lark.AccessTokenType.TENANT}) \
|
|
86
|
+
.body(body) \
|
|
87
|
+
.build()
|
|
88
|
+
|
|
89
|
+
# 发起请求
|
|
90
|
+
response: lark.BaseResponse = self.lark_client.request(request)
|
|
91
|
+
|
|
92
|
+
# 处理失败返回
|
|
93
|
+
if not response.success():
|
|
94
|
+
lark.logger.error(
|
|
95
|
+
f"client.request failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
# 处理业务结果
|
|
99
|
+
lark.logger.info(str(response.raw.content, lark.UTF_8))
|
|
100
|
+
return json.loads(response.raw.content)['data']['sheet']
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def writesheets(self, spreadsheet_token, sheet_id, data):
|
|
104
|
+
# 创建client
|
|
105
|
+
# 使用 user_access_token 需开启 token 配置, 并在 request_option 中配置 token
|
|
106
|
+
# 构造请求对象
|
|
107
|
+
# 构造请求对象
|
|
108
|
+
json_str = "{\"value_ranges\":[{\"range\":\"HEJb8z!C1:C1\",\"values\":[[[{\"text\":{\"text\":\"abc\"},\"type\":\"text\"}]]]}]}"
|
|
109
|
+
body = json.loads(json_str)
|
|
110
|
+
body = data
|
|
111
|
+
request: lark.BaseRequest = lark.BaseRequest.builder() \
|
|
112
|
+
.http_method(lark.HttpMethod.POST) \
|
|
113
|
+
.uri(
|
|
114
|
+
f"/open-apis/sheets/v3/spreadsheets/{spreadsheet_token}/sheets/{sheet_id}/values/batch_update?user_id_type=open_id") \
|
|
115
|
+
.token_types({lark.AccessTokenType.TENANT}) \
|
|
116
|
+
.body(body) \
|
|
117
|
+
.build()
|
|
118
|
+
|
|
119
|
+
# 发起请求
|
|
120
|
+
response: lark.BaseResponse = self.lark_client.request(request)
|
|
121
|
+
|
|
122
|
+
# 处理失败返回
|
|
123
|
+
if not response.success():
|
|
124
|
+
lark.logger.error(
|
|
125
|
+
f"client.request failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
# 处理业务结果
|
|
129
|
+
lark.logger.info(str(response.raw.content, lark.UTF_8))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == '__main__':
|
|
133
|
+
spreadsheet_token = ""
|
|
134
|
+
sheets = LarkdocsClient().get_the_worksheet(spreadsheet_token)
|
|
135
|
+
for i in sheets.sheets:
|
|
136
|
+
|
|
137
|
+
column_count = i.grid_properties.column_count
|
|
138
|
+
row_count = i.grid_properties.row_count
|
|
139
|
+
sheet_id = i.sheet_id
|
|
140
|
+
title = i.title
|
|
141
|
+
|
|
142
|
+
#print(column_count, row_count, sheet_id, title)
|
|
143
|
+
json_str = {"ranges": ["459f7e!A1:A1"]}
|
|
144
|
+
json_str = {"ranges": [sheet_id + "!A1:A" + str(row_count)]}
|
|
145
|
+
test = LarkdocsClient().get_plaintextcontent(json_str, spreadsheet_token, sheet_id)
|
|
146
|
+
test = json.loads(test)
|
|
147
|
+
userinput = test['data']['value_ranges'][0]['values']
|
|
148
|
+
print(f"表头为{userinput[0]}")
|
|
149
|
+
i = 0
|
|
150
|
+
for i in range(1,row_count):
|
|
151
|
+
if userinput[i][0]:
|
|
152
|
+
print(userinput[i][0])
|
|
153
|
+
else:
|
|
154
|
+
break
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
main/logger.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import logging.config
|
|
3
|
+
|
|
4
|
+
config = {
|
|
5
|
+
'version': 1,
|
|
6
|
+
'disable_existing_loggers': False,
|
|
7
|
+
'formatters': {
|
|
8
|
+
'default': {
|
|
9
|
+
'format': '%(asctime)s %(levelname)s %(message)s'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
'loggers': {
|
|
13
|
+
'playground': {
|
|
14
|
+
'handlers': ['log_agent', 'console', 'kafka_agent'],
|
|
15
|
+
'propagate': False,
|
|
16
|
+
'level': 'INFO',
|
|
17
|
+
},
|
|
18
|
+
'root': {
|
|
19
|
+
'handlers': ['log_agent', 'console'],
|
|
20
|
+
'level': 'INFO'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
'handlers': {
|
|
24
|
+
'log_agent': {
|
|
25
|
+
'level': 'INFO',
|
|
26
|
+
'class': 'bytedlogger.StreamLogHandler',
|
|
27
|
+
'tags': {
|
|
28
|
+
'customtag': 'devops_boe',
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
'kafka_agent': {
|
|
32
|
+
'level': 'INFO',
|
|
33
|
+
'class': 'kafkalogger.handlers.KafkaLogHandler',
|
|
34
|
+
'formatter': 'default',
|
|
35
|
+
},
|
|
36
|
+
'console': {
|
|
37
|
+
'level': 'INFO',
|
|
38
|
+
'class': 'logging.StreamHandler',
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
if os.getenv("DEBUG") == "true":
|
|
44
|
+
config["handlers"].pop("kafka_agent")
|
|
45
|
+
config["handlers"].pop("log_agent")
|
|
46
|
+
config["loggers"]["playground"]["handlers"].remove("kafka_agent")
|
|
47
|
+
config["loggers"]["playground"]["handlers"].remove("log_agent")
|
|
48
|
+
config['loggers']['root']['handlers'].remove("log_agent")
|
|
49
|
+
logging.config.dictConfig(config)
|
|
50
|
+
logger = logging.getLogger('playground')
|
|
51
|
+
logging.getLogger("kafka").setLevel(logging.CRITICAL)
|
|
52
|
+
logging.getLogger("bytedkafka.common.config").setLevel(logging.ERROR)
|
|
53
|
+
logging.getLogger("kafka.producer.kafka").setLevel(logging.ERROR)
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: itam_assistant
|
|
3
|
-
Version: 0.1.1
|
|
4
|
-
Summary: 新增线上设备型号接口
|
|
5
|
-
Home-page: https://github.com/liujunmeiD/it_assistant
|
|
6
|
-
Author: liujunmeiD
|
|
7
|
-
Author-email: 1105030421@qq.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.6
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
Requires-Dist: requests>=2.25.1
|
|
14
|
-
Requires-Dist: numpy>=1.20.0
|
|
15
|
-
Dynamic: author
|
|
16
|
-
Dynamic: author-email
|
|
17
|
-
Dynamic: classifier
|
|
18
|
-
Dynamic: description
|
|
19
|
-
Dynamic: description-content-type
|
|
20
|
-
Dynamic: home-page
|
|
21
|
-
Dynamic: requires-dist
|
|
22
|
-
Dynamic: requires-python
|
|
23
|
-
Dynamic: summary
|
|
24
|
-
|
|
25
|
-
详见https://bytedance.feishu.cn/docs/doccnSOL0o2qtnElftgd2rir2Dc
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
it_assistant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
it_assistant/ailyapp_client.py,sha256=_6cLF80a8SrO7LCujfHe4re7xZyt6GBbDlmApgqbK6A,6326
|
|
3
|
-
it_assistant/config.py,sha256=L_5grm2ZWwg_S1JTOU6XLhQ5GPeYJaBFBLwzP2JA5Ys,5498
|
|
4
|
-
it_assistant/do_ai.py,sha256=FRuP4yZLqBEES0PCLholdHVCbqMRlYssxT631gXRrRk,19953
|
|
5
|
-
it_assistant/intent_detail.py,sha256=xqHELgYmlZIdz6odN1AyRoE5TIPr78zCUKgiqILApOY,16914
|
|
6
|
-
it_assistant/lark_client.py,sha256=ZVDsdt7ucQvJN1-khC3TR-0IMeYaQXfdWF5DxRrkBH4,6665
|
|
7
|
-
it_assistant/logger.py,sha256=W3-tbQ4J-QKSrQSpaNBruzoyMuWYrUkrIY0uBZ1o-lw,1583
|
|
8
|
-
it_assistant/openapi.py,sha256=AJbhdbsB8PXfMjC0hFy2Nnu52dN1EGIXqoloGGD84Ig,29196
|
|
9
|
-
it_assistant/test.py,sha256=qGSihMYmtZkz_vifwEOz579f_wPBJAx5_rz1sABUyo4,581
|
|
10
|
-
itam_assistant-0.1.1.dist-info/METADATA,sha256=NMHaNgIjpYBMzFWdJDoUK-EVWBuPqqnhm6A0myX2A_Q,738
|
|
11
|
-
itam_assistant-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
-
itam_assistant-0.1.1.dist-info/top_level.txt,sha256=3g528EjzDs06L1brP8ZvVIvWFyS9K5b8gA6eRoRGdt0,13
|
|
13
|
-
itam_assistant-0.1.1.dist-info/RECORD,,
|
|
File without changes
|