From 7169ddb67824df045c20338b0312b3ae178daa3c Mon Sep 17 00:00:00 2001 From: Yuzhiran Dev Date: Mon, 18 May 2026 08:29:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20writer.py=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F=E5=86=99=E5=85=A5=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8CHTML=20=E4=BB=85=E6=8C=81=E4=B9=85=E5=8C=96?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除 RELEASE_DIR、release_dir、out_path.write_text 等文件系统相关代码, save_html 改为仅调用 save_article() 写入 articles 表。 避免后期维护时文件系统和数据库双源不一致的问题。 --- scripts/writer.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/scripts/writer.py b/scripts/writer.py index 2c67099..1da4c8f 100644 --- a/scripts/writer.py +++ b/scripts/writer.py @@ -18,7 +18,6 @@ import mistune DATA_DIR = PROJECT_ROOT / "automation" / "data" OUTLINE_DIR = DATA_DIR / "outlines" -RELEASE_DIR = DATA_DIR / "releases" TEMPLATES_DIR = PROJECT_ROOT / "automation" / "templates" LOGS_DIR = PROJECT_ROOT / "automation" / "logs" TODAY = datetime.datetime.now().strftime("%Y-%m-%d") @@ -59,8 +58,6 @@ class Writer: if not outline_file.exists(): raise FileNotFoundError(f"Outline not found: {outline_file}") self.outline_content = outline_file.read_text(encoding='utf-8') - self.release_dir = RELEASE_DIR / TODAY - self.release_dir.mkdir(parents=True, exist_ok=True) research_file = DATA_DIR / "research" / TODAY / f"{topic_id}_research.md" self.research_notes = research_file.read_text(encoding='utf-8') if research_file.exists() else "" @@ -417,19 +414,14 @@ class Writer: return html - def save_html(self, html: str, platform: str) -> Path: - out_dir = self.release_dir / platform - out_dir.mkdir(parents=True, exist_ok=True) - filename = f"{platform}_{self.topic_id}.html" - out_path = out_dir / filename - out_path.write_text(html, encoding='utf-8') - logger.info(f"HTML 生成: {out_path}") + def save_html(self, html: str, platform: str) -> str: try: save_article(self.topic_id, platform, html) logger.info(f"文章写入数据库: {platform}_{self.topic_id}") + return f"db:{platform}_{self.topic_id}" except Exception as e: logger.warning(f"数据库保存失败: {e}") - return out_path + return "" def mark_draft(self): update_topic_status(self.topic_id, 'review')