omni: менеджер источников в панели (338 источников, вкл/выкл, добавление, health-check, фоновые джобы)

This commit is contained in:
reform
2026-10-25 21:58:22 +03:00
parent e1368f2a46
commit 35be863977
9 changed files with 1173 additions and 260 deletions

View File

@@ -10,6 +10,8 @@
"""
from dataclasses import dataclass, field
from .sources_ext import EXTRA
@dataclass
class Source:
@@ -26,7 +28,7 @@ class Source:
S = Source
SOURCES = [
SOURCES_BASE = [
# ---------- papers ----------
S("arxiv_cs_ai", "papers", "rss", "https://rss.arxiv.org/rss/cs.AI", "rss", ("paper", "arxiv")),
S("arxiv_cs_lg", "papers", "rss", "https://rss.arxiv.org/rss/cs.LG", "rss", ("paper", "arxiv")),
@@ -175,12 +177,34 @@ SOURCES = [
S("tg_huggingface", "forum", "html", "https://t.me/s/huggingface", "tg_web", ("telegram",)),
]
SOURCES = SOURCES_BASE + [Source(**d) for d in EXTRA]
BY_NAME = {s.name: s for s in SOURCES}
CATEGORIES = sorted({s.category for s in SOURCES})
def pick(category=None, only=None, tags=None):
out = SOURCES
def all_sources():
"""Реестр + пользовательские источники из панели."""
from . import source_state
extra = []
for d in source_state.custom():
if d["name"] in BY_NAME:
continue
d = {k: v for k, v in d.items() if k in
("name", "category", "kind", "url", "adapter", "tags", "limit", "detail", "extra")}
extra.append(Source(**d))
return SOURCES + extra
def enabled_sources():
"""Только включённые: выключенные в панели источники не дёргаем."""
from . import source_state
fl = source_state.flags()
return [s for s in all_sources() if fl.get(s.name, {}).get("enabled", True)]
def pick(category=None, only=None, tags=None, respect_enabled=True):
out = enabled_sources() if respect_enabled else all_sources()
if category:
cats = {c.strip() for c in category.split(",") if c.strip()}
out = [s for s in out if s.category in cats]
@@ -193,8 +217,8 @@ def pick(category=None, only=None, tags=None):
return out
def stats():
def stats(use_all=True):
out = {}
for s in SOURCES:
for s in (all_sources() if use_all else SOURCES):
out.setdefault(s.category, []).append(s.name)
return {k: len(v) for k, v in sorted(out.items())}