|
@@ -1,12 +1,12 @@
|
|
|
import os
|
|
|
import json
|
|
|
import time
|
|
|
+import sys
|
|
|
+import argparse
|
|
|
from typing import Dict, Any, List, Optional
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
# 导入自定义模块
|
|
|
-import sys
|
|
|
-import os
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
from utils.fei_shu import FeiShu
|
|
@@ -14,7 +14,7 @@ from coze.coze_hook import CozeHook
|
|
|
|
|
|
|
|
|
class ContentIdentifier:
|
|
|
- def __init__(self):
|
|
|
+ def __init__(self, table_id: Optional[str] = None):
|
|
|
# 加载环境变量
|
|
|
load_dotenv()
|
|
|
|
|
@@ -24,10 +24,10 @@ class ContentIdentifier:
|
|
|
# 初始化Coze客户端
|
|
|
self.coze = CozeHook()
|
|
|
|
|
|
- # 从环境变量获取配置
|
|
|
- self.table_id = os.getenv('FEISHU_TABLE_ID')
|
|
|
+ # 获取表格ID:优先使用传入的参数,其次使用环境变量
|
|
|
+ self.table_id = table_id or os.getenv('FEISHU_TABLE_ID')
|
|
|
if not self.table_id:
|
|
|
- raise ValueError("请设置环境变量 FEISHU_TABLE_ID")
|
|
|
+ raise ValueError("请设置环境变量 FEISHU_TABLE_ID 或在运行时传入 table_id 参数")
|
|
|
|
|
|
# 字段名称配置
|
|
|
self.input_field = os.getenv('FEISHU_INPUT_FIELD', '抓取结果')
|
|
@@ -250,11 +250,36 @@ class ContentIdentifier:
|
|
|
|
|
|
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')
|
|
|
+
|
|
|
+ args = parser.parse_args()
|
|
|
+
|
|
|
try:
|
|
|
- identifier = ContentIdentifier()
|
|
|
- identifier.process_all_records()
|
|
|
+ # 创建内容识别器实例
|
|
|
+ identifier = ContentIdentifier(table_id=args.table_id)
|
|
|
+
|
|
|
+ print(f"使用表格ID: {identifier.table_id}")
|
|
|
+
|
|
|
+ if args.dry_run:
|
|
|
+ print("试运行模式:只显示会处理的记录,不实际调用API")
|
|
|
+ # TODO: 实现试运行模式
|
|
|
+ identifier.process_all_records()
|
|
|
+ else:
|
|
|
+ # 正常处理模式
|
|
|
+ if args.page_token:
|
|
|
+ print(f"从分页token开始处理: {args.page_token}")
|
|
|
+ # TODO: 支持从指定分页token开始处理
|
|
|
+ identifier.process_all_records()
|
|
|
+ else:
|
|
|
+ identifier.process_all_records()
|
|
|
+
|
|
|
except Exception as e:
|
|
|
print(f"程序执行失败: {e}")
|
|
|
+ sys.exit(1)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|