реестр: дедуп источников строго по url (2 падавших теста зелёные); инкрементальный abuse-индекс + tgsearch из предыдущей сессии
Some checks failed
ci / test (3.10) (push) Has been cancelled
ci / test (3.11) (push) Has been cancelled
ci / test (3.12) (push) Has been cancelled

This commit is contained in:
ENI
2026-10-27 01:09:30 +03:00
parent d0fca99dda
commit d0b2187319
7 changed files with 601 additions and 24 deletions

View File

@@ -89,4 +89,46 @@ def fetch(handles, limit=None):
api_id = int(os.environ["OMNI_TG_API_ID"])
api_hash = os.environ["OMNI_TG_API_HASH"]
lim = int(limit or os.environ.get("OMNI_TG_LIMIT") or 100)
return asyncio.run(_pull(list(handles), lim, session, api_id, api_hash))
return asyncio.run(_pull(list(handles), lim, session, api_id, api_hash))
async def _search(query, limit, session, api_id, api_hash, timeout=60):
"""Глобальный поиск каналов/групп по запросу (contacts.SearchRequest)."""
from telethon import TelegramClient
from telethon.tl.functions.contacts import SearchRequest
client = TelegramClient(session, api_id, api_hash, connection_retries=1, timeout=timeout / 2)
await asyncio.wait_for(client.connect(), timeout)
try:
res = await asyncio.wait_for(client(SearchRequest(q=str(query), limit=int(limit))), timeout)
out = []
for ch in getattr(res, "chats", []) or []:
uname = getattr(ch, "username", None)
if not uname:
continue
out.append({"username": uname, "title": getattr(ch, "title", "") or "",
"id": getattr(ch, "id", None),
"broadcast": bool(getattr(ch, "broadcast", False)),
"megagroup": bool(getattr(ch, "megagroup", False)),
"participants": getattr(ch, "participants_count", None) or 0,
"query": str(query)})
return out
finally:
try:
await asyncio.wait_for(client.disconnect(), 10)
except Exception:
pass
def search(query, limit=40):
"""Каналы по ключевому слову. Пусто, если сессия не настроена."""
if not enabled():
return []
try:
from . import config
config.tg_cfg()
except Exception:
pass
session = os.environ["OMNI_TG_SESSION"]
api_id = int(os.environ["OMNI_TG_API_ID"])
api_hash = os.environ["OMNI_TG_API_HASH"]
return asyncio.run(_search(query, limit, session, api_id, api_hash))