|
@@ -14,7 +14,7 @@ from utils.file import File
|
|
|
|
|
|
|
|
|
class Handler:
|
|
|
- def __init__(self, table_id: Optional[str] = None):
|
|
|
+ def __init__(self):
|
|
|
|
|
|
# 初始化飞书客户端
|
|
|
self.mysql = MysqlHelper()
|
|
@@ -22,36 +22,8 @@ class Handler:
|
|
|
self.system_prompt = File.read_file('prompt/handle.md')
|
|
|
|
|
|
# print(self.system_prompt)
|
|
|
-
|
|
|
- def extract_content_from_record(self, record) -> Dict[str, Any]:
|
|
|
- """从飞书记录中提取内容"""
|
|
|
- fields = record.fields
|
|
|
-
|
|
|
- # 提取识别结果
|
|
|
- result = fields.get(self.input_field, [])
|
|
|
-
|
|
|
- return ''.join([item['text'] for item in result])
|
|
|
|
|
|
|
|
|
- def update_feishu_record(self, record_id: str, content: str):
|
|
|
- """更新飞书表格中的记录"""
|
|
|
- try:
|
|
|
- import lark_oapi as lark
|
|
|
- # 创建更新记录
|
|
|
- update_record = (lark.bitable.v1.AppTableRecord.builder()
|
|
|
- .record_id(record_id)
|
|
|
- .fields({
|
|
|
- self.output_field: content
|
|
|
- })
|
|
|
- .build())
|
|
|
-
|
|
|
- # 执行更新
|
|
|
- self.feishu.update_record(self.table_id, update_record)
|
|
|
- print(f"已更新记录 {record_id}")
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- print(f"更新飞书记录失败: {e}")
|
|
|
-
|
|
|
def process_single_record(self, record) -> bool:
|
|
|
"""处理单条记录"""
|
|
|
try:
|
|
@@ -121,20 +93,18 @@ class Handler:
|
|
|
def main():
|
|
|
"""主函数"""
|
|
|
# 创建命令行参数解析器
|
|
|
- parser = argparse.ArgumentParser(description='内容识别脚本 - 处理飞书表格数据')
|
|
|
- parser.add_argument('--table_id', nargs='?', help='飞书表格ID (可选,也可通过环境变量 FEISHU_TABLE_ID 设置)')
|
|
|
- parser.add_argument('--page-token', help='分页token,用于从指定位置开始处理')
|
|
|
- parser.add_argument('--dry-run', action='store_true', help='试运行模式,只显示会处理哪些记录,不实际调用API')
|
|
|
+ parser = argparse.ArgumentParser(description='内容识别脚本')
|
|
|
+ parser.add_argument('--query_word', nargs='?', help='query词')
|
|
|
+ parser.add_argument('--source_type', nargs='?', help='数据源类型')
|
|
|
+ parser.add_argument('--source_channel', nargs='?', help='数据源渠道')
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
try:
|
|
|
# 创建内容识别器实例
|
|
|
- hadnler = Handler(table_id=args.table_id)
|
|
|
-
|
|
|
- print(f"使用表格ID: {hadnler.table_id}")
|
|
|
+ hadnler = Handler()
|
|
|
|
|
|
- hadnler.process_all_records()
|
|
|
+ hadnler.process_all_records(query_word=args.query_word, source_type=source_type, source_channel=source_channel)
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"程序执行失败: {e}")
|