feat(rewrite): auto-rewrite stale selected posts, sources in bundle frontmatter

This commit is contained in:
kpa39l
2026-11-05 10:01:14 +00:00
parent 97dcd804f9
commit 17b6973ef0
16 changed files with 676 additions and 6 deletions
+6 -4
View File
@@ -75,7 +75,8 @@ def _kind_of(url: str) -> str:
def _insert_suggestion(conn, post_id: int, url: str, *, kind: str | None = None,
title: str | None = None, snippet: str | None = None,
score: float | None = None, reason: str | None = None) -> bool:
score: float | None = None, reason: str | None = None,
origin: str = "search") -> bool:
"""Добавляет кандидата, не перетирая существующего (accepted/rejected сохраняются)."""
url = (url or "").strip()
if not url:
@@ -83,11 +84,11 @@ def _insert_suggestion(conn, post_id: int, url: str, *, kind: str | None = None,
domain = (urlparse(url).netloc or "").lower().removeprefix("www.")
cur = conn.execute(
"INSERT INTO post_source_suggestions"
" (post_id, url, domain, kind, title, snippet, score, reason, status, created_at)"
" VALUES (?,?,?,?,?,?,?,?,'suggested',?)"
" (post_id, url, domain, kind, title, snippet, score, reason, status, created_at, origin)"
" VALUES (?,?,?,?,?,?,?,?,'suggested',?,?)"
" ON CONFLICT(post_id, url) DO NOTHING",
(post_id, url, domain, kind or _kind_of(url), (title or "")[:300], (snippet or "")[:400],
score, reason, fmt(now_local())),
score, reason, fmt(now_local()), origin),
)
return cur.rowcount > 0
@@ -213,6 +214,7 @@ def find_sources(conn, post: dict) -> dict:
snippet="",
score=0.9,
reason="ссылка в тексте поста",
origin="text",
):
result["added"] += 1
result["from_text"] += 1