omni: редизайн панели + 450 источников (341 живых), health-аудит, чистка html/дат, per-source учёт
This commit is contained in:
@@ -150,6 +150,29 @@ def browse(category=None, q="", limit=60, offset=0):
|
||||
return [dict(zip(keys, r)) for r in rows]
|
||||
|
||||
|
||||
def browse2(q="", names=None, limit=60, offset=0, sort="score"):
|
||||
"""Записи для панели: фильтр по списку источников (категория), подстрока, пагинация + total."""
|
||||
where = "WHERE 1=1 "
|
||||
args = []
|
||||
if names:
|
||||
where += "AND source IN (%s) " % ",".join("?" * len(names))
|
||||
args += list(names)
|
||||
if q:
|
||||
where += "AND (title LIKE ? OR text LIKE ?) "
|
||||
args += [f"%{q}%", f"%{q}%"]
|
||||
with conn() as c:
|
||||
total = c.execute("SELECT COUNT(*) FROM items " + where, args).fetchone()[0]
|
||||
rows = c.execute("SELECT provider,kind,source,title,text,author,published,score,price,currency,url "
|
||||
"FROM items " + where + ("ORDER BY published DESC, id DESC LIMIT ? OFFSET ?" if sort == "fresh" else "ORDER BY score DESC, id DESC LIMIT ? OFFSET ?"),
|
||||
args + [limit, offset]).fetchall()
|
||||
keys = ("provider", "kind", "source", "title", "text", "author", "published", "score", "price", "currency", "url")
|
||||
return [dict(zip(keys, r)) for r in rows], total
|
||||
|
||||
|
||||
def count_by_source():
|
||||
with conn() as c:
|
||||
return dict(c.execute("SELECT source, COUNT(*) FROM items GROUP BY source").fetchall())
|
||||
|
||||
def stats():
|
||||
with conn() as c:
|
||||
total = c.execute("SELECT COUNT(*) FROM items").fetchone()[0]
|
||||
|
||||
Reference in New Issue
Block a user