feat(publish): 30-min slot grid with silent slots and loud morning/evening anchors
This commit is contained in:
+15
-2
@@ -15,6 +15,7 @@ from config import (
|
||||
AUTOREWRITE_ENQUEUE,
|
||||
AUTOREWRITE_HOURS,
|
||||
AUTOREWRITE_MIN_TEXT,
|
||||
AUTOREWRITE_MAX_AGE_DAYS,
|
||||
AUTOREWRITE_QUEUE_DAYS,
|
||||
FIND_SOURCES_ENABLED,
|
||||
)
|
||||
@@ -96,10 +97,11 @@ def stale_posts(conn: sqlite3.Connection, hours: int | None = None,
|
||||
AND (p.rewritten_text IS NULL OR p.rewritten_text = '')
|
||||
AND length(COALESCE(p.text, '')) >= ?
|
||||
AND COALESCE(p.selected_at, p.fetched_at) <= datetime('now', ?)
|
||||
AND COALESCE(p.fetched_at, p.selected_at) >= datetime('now', ?)
|
||||
ORDER BY COALESCE(p.selected_at, p.fetched_at) ASC
|
||||
LIMIT ?
|
||||
""",
|
||||
(AUTOREWRITE_MIN_TEXT, f"-{hours} hours", limit),
|
||||
(AUTOREWRITE_MIN_TEXT, f"-{hours} hours", f"-{AUTOREWRITE_MAX_AGE_DAYS} days", limit),
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
@@ -134,6 +136,16 @@ def topup_queue(conn: sqlite3.Connection, live: bool) -> int:
|
||||
return added
|
||||
|
||||
|
||||
def expired_posts(conn: sqlite3.Connection) -> int:
|
||||
"""Сколько отобранных постов уже старше допустимого возраста (не публикуем, ждут решения)."""
|
||||
row = conn.execute(
|
||||
"SELECT COUNT(*) c FROM posts WHERE status='selected' "
|
||||
"AND COALESCE(fetched_at, selected_at) < datetime('now', ?)",
|
||||
(f"-{AUTOREWRITE_MAX_AGE_DAYS} days",),
|
||||
).fetchone()
|
||||
return int(row["c"] or 0)
|
||||
|
||||
|
||||
def hours_in_selected(post: dict) -> float:
|
||||
"""Сколько часов пост в «Отобранных». selected_at пишется в UTC (datetime('now') в SQLite)."""
|
||||
stamp = post.get("selected_at") or post.get("fetched_at") or ""
|
||||
@@ -214,7 +226,8 @@ def run(conn: sqlite3.Connection, *, live: bool | None = None,
|
||||
from config import AUTOREWRITE_LIVE
|
||||
live = AUTOREWRITE_LIVE if live is None else live
|
||||
posts = stale_posts(conn, hours=hours, limit=limit)
|
||||
summary = {"live": live, "found": len(posts), "reports": [], "queued_topup": 0}
|
||||
summary = {"live": live, "found": len(posts), "reports": [], "queued_topup": 0,
|
||||
"expired": expired_posts(conn)}
|
||||
# сначала дозаправляем очередь уже переписанными, чтобы слоты не простаивали
|
||||
summary["queued_topup"] = topup_queue(conn, live)
|
||||
for post in posts:
|
||||
|
||||
Reference in New Issue
Block a user