docs: 文档重构 — 清理 AI agent 残留,整合 docs/ 目录结构
- 删除 11 个残留文件: continuation.md, init_plan.md, reasonix.toml, djapi/continuation.md, djapi/.serena/, djapi/.claude/, djapi/.mcp.json, .claude/skills/, docs/usage.html, docs/db_schema.md, docs/report_db_design.md - 7 个 CLAUDE-*.md 移入 docs/ 并重命名去 CLAUDE- 前缀 - 新增 4 个文档: architecture.md, development.md, api.md, deployment.md - 重写 usage.md, README.md - 修复所有过时引用和交叉链接
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
news_report / news_event 只读查询层(日报结构化入库,见 docs/db_schema.md)。
|
||||
news_report / news_event 只读查询层(日报结构化入库,见 docs/db_schema_v1.1.md)。
|
||||
|
||||
连接配置来自环境变量(与 docs/report_db_design.md §7 保持一致):
|
||||
连接配置来自环境变量(与 docs/db_schema_v1.1.md 保持一致):
|
||||
NEWS_DB_HOST / NEWS_DB_PORT / NEWS_DB_USER / NEWS_DB_PASSWORD / NEWS_DB_NAME
|
||||
NEWS_DB_PASSWORD 缺失时直接报错,禁止默认密码。
|
||||
|
||||
@@ -45,6 +45,18 @@ def _connect():
|
||||
return mysql.connector.connect(**load_db_config())
|
||||
|
||||
|
||||
def _parse_json(value):
|
||||
"""把 JSON 字符串列(如 sources)解析为 dict/list;已是对象则原样返回。"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
return value
|
||||
|
||||
|
||||
def _row_to_dict(row: dict) -> dict:
|
||||
"""序列化行:stats JSON 解析、日期/时间转 ISO 字符串。"""
|
||||
d = dict(row)
|
||||
@@ -87,11 +99,14 @@ def fetch_reports(
|
||||
report = _row_to_dict(row)
|
||||
cur.execute(
|
||||
"SELECT id, section, rank, importance, event_type, title, "
|
||||
"summary, sentiment, source, url "
|
||||
"summary, sentiment, source, sources, url "
|
||||
"FROM news_event WHERE report_id = %s ORDER BY section, rank",
|
||||
(report_id,),
|
||||
)
|
||||
report["events"] = [dict(r) for r in cur.fetchall()]
|
||||
report["events"] = [
|
||||
{**dict(r), "sources": _parse_json(r["sources"])}
|
||||
for r in cur.fetchall()
|
||||
]
|
||||
return report
|
||||
|
||||
where, params = [], []
|
||||
@@ -153,7 +168,7 @@ def fetch_important_events(
|
||||
sql = (
|
||||
"SELECT r.report_date, r.report_type, e.id, e.section, e.rank, "
|
||||
"e.importance, e.event_type, e.title, e.summary, e.sentiment, "
|
||||
"e.source, e.url "
|
||||
"e.source, e.sources, e.url "
|
||||
"FROM news_event e "
|
||||
"JOIN news_report r ON r.id = e.report_id "
|
||||
"WHERE " + " AND ".join(where)
|
||||
@@ -163,6 +178,10 @@ def fetch_important_events(
|
||||
)
|
||||
params.append(int(limit))
|
||||
cur.execute(sql, tuple(params))
|
||||
return [dict(r) for r in cur.fetchall()]
|
||||
rows = cur.fetchall()
|
||||
return [
|
||||
{**dict(r), "sources": _parse_json(r["sources"])}
|
||||
for r in rows
|
||||
]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user