Files
omni-parse/omni/config.py
ENI 2b9f4e1d88
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
дарк-форумы + cookie-проход CF + opt_in радара в обходе
- omni/sources_dark.py: cracked.st, nulledbb, forum.tuts4you — реально отдают темы без логина
- tools/cf_cookies.py: Camoufox снимает cookies с JS-челленджей в data/cookies.json (вне git)
- config: cookies.json подхватывается автоматически
- feeds: include_contains матчится по полному href (showthread.php?tid= не резался по path)
- sources_abuse/abuse_sources: A(extra=...) + tuts4you на html_listing (/topic/)
- sources: _gen_sources() = китайские + дарк наборы
- README: ключи/радар/китайцы/дарк
2026-10-26 23:39:47 +03:00

106 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Конфиг: пути, лимиты, ключи из env/.env. Никаких секретов в коде."""
import json
import os
import pathlib
ROOT = pathlib.Path(__file__).resolve().parent.parent
DATA = pathlib.Path(os.environ.get("OMNI_DATA") or (ROOT / "data"))
DB = pathlib.Path(os.environ.get("OMNI_DB") or (DATA / "omni.sqlite3"))
THEMES = ROOT / "themes.txt"
DEFAULTS = {
"timeout": 25,
"retries": 2,
"per_host_delay": 0.6,
"max_bytes": 4_000_000,
"limit": 20,
"lang": "ru",
"ua": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"),
"proxy_mode": "off", # off | list | env
"proxies": [],
"cookies": {}, # host -> "a=b; c=d" (свои сессии к закрытым площадкам)
}
KEYS = {} # имя -> значение
CONFIG = {} # прочие настройки
def cookies_for(host):
"""Cookie-строка под хост: точное совпадение или суффикс (example.com -> www.example.com)."""
ck = CONFIG.get("cookies") or {}
if not ck:
return ""
host = (host or "").lower().split(":")[0]
if host in ck:
return ck[host]
for k, v in ck.items():
k = k.lower().lstrip(".")
if host == k or host.endswith("." + k):
return v
return ""
def _load_env_file(path):
p = pathlib.Path(path)
if not p.exists():
return {}
out = {}
for line in p.read_text(encoding="utf-8", errors="ignore").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
k, v = line.split("=", 1)
out[k.strip()] = v.strip().strip('"').strip("'")
return out
def load():
"""Читает .env рядом с проектом и config.json (если есть), собирает ключи."""
global KEYS, CONFIG
envf = _load_env_file(ROOT / ".env")
for k, v in envf.items():
os.environ.setdefault(k, v)
cfg = dict(DEFAULTS)
cf = ROOT / "config.json"
if cf.exists():
try:
cfg.update(json.loads(cf.read_text(encoding="utf-8")))
except Exception:
pass
CONFIG = cfg
# cookies, снятые браузером (tools/cf_cookies.py) — файл вне git
ck_file = DATA / "cookies.json"
if ck_file.exists():
try:
extra = json.loads(ck_file.read_text(encoding="utf-8"))
if isinstance(extra, dict):
cfg["cookies"] = {**extra, **(cfg.get("cookies") or {})}
except Exception:
pass
raw = os.environ.get("OMNI_COOKIES") or ""
if raw:
try:
extra = json.loads(raw)
if isinstance(extra, dict):
cfg["cookies"] = {**(cfg.get("cookies") or {}), **extra}
except Exception:
pass
for name in ("TAVILY_API_KEY", "EXA_API_KEY", "YOU_API_KEY", "FIRECRAWL_API_KEY",
"JINA_API_KEY", "SERPER_API_KEY", "BRAVE_API_KEY", "X_BEARER",
"REDDIT_CLIENT_ID", "REDDIT_SECRET", "TREG_TOKEN", "GITHUB_TOKEN"):
v = os.environ.get(name)
if v:
KEYS[name] = v
DATA.mkdir(parents=True, exist_ok=True)
return cfg
def proxies():
mode = CONFIG.get("proxy_mode", "off")
if mode == "env":
v = os.environ.get("OMNI_PROXIES", "")
return [x.strip() for x in v.split(",") if x.strip()]
if mode == "list":
return list(CONFIG.get("proxies") or [])
return []