feat(tg): своя сессия Telethon — omni/tgsess.py + omni pump (глубина 200 постов вместо 20, 20 каналов -> 2832 поста, 2592 новых), CVE-ID в заголовке (471), tg_alive_audit из 856 сессий нашёл 121 живую; тесты 22
This commit is contained in:
36
omni/cli.py
36
omni/cli.py
@@ -8,6 +8,7 @@ import sys
|
||||
from . import config, rank, store
|
||||
from . import feeds, sources
|
||||
from . import filter as flt
|
||||
from .model import Item
|
||||
from .providers import FUNCS, MODULES, get, status
|
||||
|
||||
ALL_FREE = ["reddit", "x", "forums", "ddg", "mojeek", "bing"]
|
||||
@@ -268,6 +269,35 @@ def cmd_dedupe(a):
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_pump(a):
|
||||
"""История Telegram-каналов через свою сессию (нужны OMNI_TG_SESSION/API_ID/API_HASH)."""
|
||||
from . import tgsess
|
||||
if not tgsess.enabled():
|
||||
print("нет сессии: задай OMNI_TG_SESSION, OMNI_TG_API_ID, OMNI_TG_API_HASH")
|
||||
return 2
|
||||
handles = [h.strip() for h in a.channels.split(",") if h.strip()]
|
||||
recs = tgsess.fetch(handles, a.limit)
|
||||
if not recs:
|
||||
print("пусто")
|
||||
return 1
|
||||
items = []
|
||||
for r in recs:
|
||||
for post in r.get("posts") or []:
|
||||
if len(post["text"]) < 12:
|
||||
continue
|
||||
items.append(Item("tg_" + r["handle"], "post", url=post["url"], title=post["title"],
|
||||
text=post["text"], author="@" + r["handle"],
|
||||
published=post["date"], source="tg_" + r["handle"],
|
||||
extra={"views": post.get("views"), "via": "session"}))
|
||||
print("каналов %d, постов %d" % (len(recs), len(items)))
|
||||
if not a.apply:
|
||||
print("dry-run: добавь --apply")
|
||||
return 0
|
||||
new, dup = store.add(items)
|
||||
print("новых %d, дублей %d" % (new, dup))
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
@@ -369,6 +399,12 @@ def main(argv=None):
|
||||
sp.add_argument("--apply", action="store_true", help="реально удалить лишние строки")
|
||||
sp.set_defaults(fn=cmd_dedupe)
|
||||
|
||||
sp = sub.add_parser("pump", help="история Telegram-каналов через свою сессию")
|
||||
sp.add_argument("channels", help="каналы через запятую")
|
||||
sp.add_argument("--limit", type=int, default=100)
|
||||
sp.add_argument("--apply", action="store_true")
|
||||
sp.set_defaults(fn=cmd_pump)
|
||||
|
||||
args = p.parse_args(argv)
|
||||
return args.fn(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user