refactor: writer.py 移除文件系统写入代码,HTML 仅持久化到数据库
删除 RELEASE_DIR、release_dir、out_path.write_text 等文件系统相关代码, save_html 改为仅调用 save_article() 写入 articles 表。 避免后期维护时文件系统和数据库双源不一致的问题。
This commit is contained in:
+3
-11
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user