abuse: классификатор ловит панели/github/hn и мульти-теги, реальный total из индекса, кап API поднят до 3000
This commit is contained in:
@@ -59,11 +59,37 @@ def probe_one(src, limit):
|
||||
"samples": [{"title": i.title[:160], "url": i.url[:200]} for i in items[:3]]}
|
||||
|
||||
|
||||
def emit(rows, dead, path):
|
||||
def _norm(u):
|
||||
u = u.strip().lower().rstrip("/")
|
||||
for pre in ("https://", "http://"):
|
||||
if u.startswith(pre):
|
||||
u = u[len(pre):]
|
||||
return u[4:] if u.startswith("www.") else u
|
||||
|
||||
|
||||
def _registry_urls():
|
||||
from omni.sources import all_sources
|
||||
out = set()
|
||||
for s in all_sources():
|
||||
out.add(_norm(s.url))
|
||||
out.add(_norm(s.url).split("?")[0])
|
||||
return out
|
||||
|
||||
|
||||
def emit(rows, dead, path, dedupe=True):
|
||||
"""omni/sources_fresh.py: только живые, без импортов из omni.sources."""
|
||||
def q(s):
|
||||
return '"%s"' % str(s).replace('"', '\\"')
|
||||
|
||||
if dedupe:
|
||||
have = _registry_urls()
|
||||
kept, skipped = [], []
|
||||
for r in rows:
|
||||
n = _norm(r["url"])
|
||||
(skipped if (n in have or n.split("?")[0] in have) else kept).append(r)
|
||||
print("emit: уже есть в реестре -> %d: %s" % (len(skipped), ", ".join(r["name"] for r in skipped)))
|
||||
rows = kept
|
||||
|
||||
lines = [
|
||||
'"""Свежая волна источников omni: security/CVE/leaks/CN/RU/tg.',
|
||||
"",
|
||||
@@ -104,8 +130,19 @@ def main():
|
||||
ap.add_argument("--out", default="data/fresh_probe.json")
|
||||
ap.add_argument("--emit", action="store_true")
|
||||
ap.add_argument("--fresh", action="store_true", help="прогонять только то, что уже в sources_fresh.py")
|
||||
ap.add_argument("--emit-only", action="store_true", help="перегенерировать sources_fresh.py из готового JSON")
|
||||
ap.add_argument("--no-dedupe", action="store_true", help="не отбрасывать источники, уже присутствующие в реестре")
|
||||
a = ap.parse_args()
|
||||
|
||||
if a.emit_only:
|
||||
rep = json.loads((ROOT / a.out).read_text(encoding="utf-8"))
|
||||
rows = rep["results"]
|
||||
alive = [r for r in rows if r["ok"]]
|
||||
dead = [r for r in rows if not r["ok"]]
|
||||
n = emit(alive, dead, ROOT / "omni" / "sources_fresh.py", dedupe=not a.no_dedupe)
|
||||
print("omni/sources_fresh.py: %d источников" % n)
|
||||
return 0
|
||||
|
||||
cands = [c for c in CANDIDATES if not a.only or a.only in c["name"]]
|
||||
srcs = []
|
||||
for c in cands:
|
||||
@@ -137,7 +174,7 @@ def main():
|
||||
print(" dead %-24s %s" % (r["name"], r["err"][:110]))
|
||||
|
||||
if a.emit:
|
||||
n = emit(alive, dead, ROOT / "omni" / "sources_fresh.py")
|
||||
n = emit(alive, dead, ROOT / "omni" / "sources_fresh.py", dedupe=not a.no_dedupe)
|
||||
print("omni/sources_fresh.py: %d источников" % n)
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user