This commit is contained in:
Daniel
2026-03-04 16:48:17 +08:00
parent 64f4c438c3
commit 26938449f0
34 changed files with 956 additions and 500 deletions

View File

@@ -4,6 +4,7 @@ import sqlite3
import hashlib
import os
from datetime import datetime, timezone
from typing import Optional
from config import DB_PATH
@@ -73,14 +74,29 @@ def touch_situation_updated_at(conn: sqlite3.Connection) -> None:
conn.commit()
def write_updates(updates: list[dict]) -> int:
def touch_situation_updated_at_path(db_path: Optional[str] = None) -> bool:
"""仅更新 situation.updated_at 为当前时间(每次爬虫运行都调用,便于前端显示「最后抓取时间」)。返回是否成功。"""
path = db_path or DB_PATH
if not os.path.exists(path):
return False
conn = sqlite3.connect(path, timeout=10)
try:
touch_situation_updated_at(conn)
return True
finally:
conn.close()
def write_updates(updates: list[dict], db_path: Optional[str] = None) -> int:
"""
updates: [{"title","summary","url","published","category","severity"}, ...]
db_path: 与 pipeline 一致,缺省用 config.DB_PATH
返回新增条数。
"""
if not os.path.exists(DB_PATH):
path = db_path or DB_PATH
if not os.path.exists(path):
return 0
conn = sqlite3.connect(DB_PATH, timeout=10)
conn = sqlite3.connect(path, timeout=10)
try:
count = 0
for u in updates: