fix: video 模块与 continuation 状态更新

Co-Authored-By: Simon <simon@doorcome.cn>
This commit is contained in:
2026-06-17 20:48:42 +08:00
co-authored by Simon
parent 2f1d8b4d03
commit bb1a9c4470
3 changed files with 43 additions and 16 deletions
+6 -3
View File
@@ -162,7 +162,7 @@ def transcribe_audio(audio_path):
# 确保音频文件存在 # 确保音频文件存在
if not os.path.exists(audio_path): if not os.path.exists(audio_path):
logger.error(f"音频文件不存在: {audio_path}") logger.error(f"音频文件不存在: {audio_path}")
return "" return ['', '']
dashscope.api_key = os.getenv('DASHSCOPE_API_KEY', '') dashscope.api_key = os.getenv('DASHSCOPE_API_KEY', '')
# 创建识别对象 # 创建识别对象
recognition = Recognition( recognition = Recognition(
@@ -187,10 +187,10 @@ def transcribe_audio(audio_path):
return text return text
else: else:
logger.error(f"❌ 任务失败: {result.message}") logger.error(f"❌ 任务失败: {result.message}")
return "" return ['', '']
except Exception as e: except Exception as e:
logger.error(f"识别过程中发生异常: {e}") logger.error(f"识别过程中发生异常: {e}")
return "" return ['', '']
def merge_transcripts(transcripts): def merge_transcripts(transcripts):
""" """
@@ -287,6 +287,9 @@ def analyze_and_correct_text(text):
# 首先修正文本错误 # 首先修正文本错误
corrected_text = text_correction(text) corrected_text = text_correction(text)
if corrected_text is None:
logger.warning("文本修正返回 None,使用原始文本")
corrected_text = text
logger.info(f"原始文本长度: {len(text)}") logger.info(f"原始文本长度: {len(text)}")
logger.info(f"修正后文本长度: {len(corrected_text)}") logger.info(f"修正后文本长度: {len(corrected_text)}")
+18 -1
View File
@@ -86,7 +86,24 @@ def news_to_db(target_date):
prompt= "###请根据下面新闻内容的文本逻辑 \n - 帮我分割成各个独立的新闻内容(注意:不要修改新闻本身,仅分割文本),并给每个新闻总结一个标题; \n - 如果遇到'国内快讯''国际快讯''联播快讯',也请根据每个条快讯分割为一个新闻以及新闻标题; \n - 返回json格式。json格式包含:news_idnews_titlenews_content; news_id从1开始递增。" prompt= "###请根据下面新闻内容的文本逻辑 \n - 帮我分割成各个独立的新闻内容(注意:不要修改新闻本身,仅分割文本),并给每个新闻总结一个标题; \n - 如果遇到'国内快讯''国际快讯''联播快讯',也请根据每个条快讯分割为一个新闻以及新闻标题; \n - 返回json格式。json格式包含:news_idnews_titlenews_content; news_id从1开始递增。"
try: try:
response = deepseek_text(result, prompt) response = deepseek_text(result, prompt)
news_list = json.loads(response) data = json.loads(response)
# DeepSeek json_object 模式返回的是 dict(如 {"news": [...]}),
# 普通模式返回的是纯数组 [...],这里做自适应提取
if isinstance(data, dict):
# 从 dict 中提取列表:找第一个 list 类型的 value
news_list = None
for v in data.values():
if isinstance(v, list):
news_list = v
break
if news_list is None:
# 所有 value 都不是 list,可能是 {"1": {...}, "2": {...}} 格式
news_list = list(data.values())
elif isinstance(data, list):
news_list = data
else:
raise ValueError(f"不支持 DeepSeek 响应格式: {type(data)}")
db = MySQLDB() db = MySQLDB()
for news in news_list: for news in news_list:
db.insert_data( db.insert_data(
+19 -12
View File
@@ -2,7 +2,7 @@
## 当前项目状态 ## 当前项目状态
djapi — Django 5.2 金融数据 API 项目,2026-06-03 已部署。 djapi — Django 5.2 金融数据 API 项目,2026-06-17 已部署。
服务器:`simon@doorcome.cn`,路径 `/home/simon/myquant/djapi/`,虚拟环境 `/opt/miniconda/envs/django/` 服务器:`simon@doorcome.cn`,路径 `/home/simon/myquant/djapi/`,虚拟环境 `/opt/miniconda/envs/django/`
@@ -20,37 +20,43 @@ djapi — Django 5.2 金融数据 API 项目,2026-06-03 已部署。
- `api/stock/config.py`:拆分为 config / strategy_config / scan_config - `api/stock/config.py`:拆分为 config / strategy_config / scan_config
### 3. drf-spectacular 集成 ### 3. drf-spectacular 集成
- 15 端点 `@api_view` + `@extend_schema`8 tag 分组 - 14 端点 `@api_view` + `@extend_schema`8 tag 分组
- 13 SerializerSwagger `/api/docs/` - 13 SerializerSwagger `/api/docs/`
### 4. 新功能 ### 4. 股息率 API 优化
- akshare 股息率 API`api/stock/getDivData_AK.py``GET /api/getdivak/` - **删除** `api/stock/getDivData_AK.py`akshare 版)`/api/getdivak/` 路由移除
- **优化** `api/stock/getStockDiv2.py`
- TTM 计算:`calculate_ttm_div` 行级循环 O(n²) → `rolling('360D').sum()` O(n)
- 删除向前填充逻辑(~30 行),避免与毛刺平滑冲突
- **修复** `api/stock/smoothBrush.py`if/elif 分支中 prev_valid/next_valid 赋值反了
### 5. video 模块重构 ### 5. video 模块重构与 Bug 修复
- 新增 `api/video/env.py` — .env 加载 - 新增 `api/video/env.py` — .env 加载
- `newsRedo.py` 重写 — 三分支智能重处理 - `newsRedo.py` 重写 — 三分支智能重处理
- **P0 修复**`getVideo5.py` 日期校验 bug`start_date > start_date``start_date > end_date` - **P0 修复**`getVideo5.py` 日期校验 bug`start_date > start_date``start_date > end_date`
- **P1 清理**:删除 `ai.py`(两个函数均为死代码),清理 `newsProcess.py` 冗余 import - **P1 清理**:删除 `ai.py`(两个函数均为死代码),清理 `newsProcess.py` 冗余 import
- **P2 修复**`audioRead.py``transcribe_audio` 异常时返回 `['', '']` 统一类型;`analyze_and_correct_text` 防御 None
- **P3 修复**`newsProcess.py``news_to_db()` JSON 解析自适应 dict/listDeepSeek json_object 模式返回 dict 包装)
### 6. 文档与测试 ### 6. 文档与测试
- `CLAUDE.md``README.md``continuation.md` - `CLAUDE.md``README.md``continuation.md`
- 18 个单元测试 - 18 个单元测试
## video 目录文件现状(9 个 .py ## video 目录文件现状(10 个 .py
| 文件 | 职责 | | 文件 | 职责 |
|------|------| |------|------|
| `env.py` | .env 加载 | | `env.py` | .env 加载 |
| `getVideo5.py` | 主流程:抓取→下载→ASR→入库 | | `getVideo5.py` | 主流程:抓取→下载→ASR→入库 |
| `audioRead.py` | 音频转换、分割、ASR 识别 | | `audioRead.py` | 音频转换、分割、ASR 识别、文本纠错 |
| `deepseek.py` | DeepSeek API 封装(类 + 函数 | | `deepseek.py` | DeepSeek API 封装(类 + `deepseek_text` 函数,支持 `response_format` |
| `newsProcess.py` | AI 新闻分割+标题提取 | | `newsProcess.py` | AI 新闻分割+标题提取JSON 自适应解析 |
| `newsRedo.py` | 手动重处理(三分支) | | `newsRedo.py` | 手动重处理(三分支) |
| `main.py` | 定时任务入口(当天) | | `main.py` | 定时任务入口(当天) |
| `main_videos.py` | 批量补缺(扫描缺失日期) | | `main_videos.py` | 批量补缺(扫描缺失日期) |
| `mysqlHandle.py` | MySQLDB 重新导出 | | `mysqlHandle.py` | MySQLDB 重新导出 |
## 所有 API 端点(15 个) ## 所有 API 端点(14 个)
| 端点 | 数据源 | 说明 | | 端点 | 数据源 | 说明 |
|------|--------|------| |------|--------|------|
@@ -65,8 +71,7 @@ djapi — Django 5.2 金融数据 API 项目,2026-06-03 已部署。
| `dailymargin/` | Tushare | 每日融资融券汇总 | | `dailymargin/` | Tushare | 每日融资融券汇总 |
| `stockmargin/` | Tushare | 个股融资融券 | | `stockmargin/` | Tushare | 个股融资融券 |
| `finance/` | Tushare | 财务报表分析 | | `finance/` | Tushare | 财务报表分析 |
| `getdiv/` | Tushare | 股息率 | | `getdiv/` | Tushare | 股息率TTM rolling + 毛刺平滑) |
| `getdivak/` | akshare | 股息率(无需 token |
| `xwlbNews/` | MySQL | 新闻联播原始文本 | | `xwlbNews/` | MySQL | 新闻联播原始文本 |
| `xwlbFine/` | MySQL | 新闻联播 AI 精编 | | `xwlbFine/` | MySQL | 新闻联播 AI 精编 |
@@ -94,3 +99,5 @@ ssh simon@doorcome.cn "kill \$(lsof -ti:5004); sleep 2; /opt/miniconda/envs/djan
- video 模块保护、向后兼容优先、不使用 python-dotenv - video 模块保护、向后兼容优先、不使用 python-dotenv
- rsync 陷阱:多文件源会展平路径 - rsync 陷阱:多文件源会展平路径
- `.env` 双加载:Django 端 `djapi/env_loader.py` + video 端 `api/video/env.py` - `.env` 双加载:Django 端 `djapi/env_loader.py` + video 端 `api/video/env.py`
- 股息率 TTM 用 `rolling('360D').sum()` 向量化,不手动循环
- DeepSeek json_object 模式返回 dictnewsProcess 自适应提取 list