- EventRow 新增 sources 字段;init_schema 幂等 ALTER 补列(MariaDB) - save_report 写入 sources JSON;_article_sources_full 完整来源列表 - source 字段保持 ≤3 拼接兼容;新增多源完整列表测试 - 已部署 pi5:sources 列写入验证通过(单源数组);完整多源待新数据
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""日报结构化入库:数据模型。
|
|
|
|
与 news 项目 report_db/models.py 保持一致(intl 板块复用同一表结构)。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class EventRow(BaseModel):
|
|
"""一条事件记录,对应 news_event 一行。"""
|
|
|
|
section: str # xwlb | news | cninfo | intl
|
|
rank: int # 板块内序号(从 1 开始)
|
|
importance: int | None = None
|
|
event_type: str | None = None
|
|
title: str
|
|
summary: str | None = None
|
|
sentiment: str | None = None # positive | negative | neutral | ''
|
|
source: str | None = None
|
|
sources: list[str] = Field(
|
|
default_factory=list,
|
|
description="全部来源展示名(JSON 数组,主源居首;多源新闻记录完整列表)",
|
|
)
|
|
url: str | None = None
|
|
|
|
|
|
class ReportData(BaseModel):
|
|
"""一份完整日报:news_report 一行 + news_event 多行。"""
|
|
|
|
report_date: date
|
|
report_type: str # finance | intl
|
|
file_name: str = "" # 源文件名(新生成日报可为空)
|
|
generated_at: datetime
|
|
ai_summary: str | None = None
|
|
stats: dict[str, Any] = Field(default_factory=dict)
|
|
events: list[EventRow] = Field(default_factory=list)
|