From 9680235ccc121d70cd26831555da0b2c27049c80 Mon Sep 17 00:00:00 2001 From: kpa39l Date: Sat, 3 Oct 2026 16:20:04 +0000 Subject: [PATCH] =?UTF-8?q?mastodon-crawler:=20=D0=BF=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20(MASTODON=5FACCESS=5FTOKEN)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .env: MASTODON_ACCESS_TOKEN (gitignored, не коммитится) - config.py: MASTODON_ACCESS_TOKEN из env - crawler/mastodon_crawler.py: Authorization: Bearer в заголовках, если токен задан (снимает 422 с /timelines/public на mastodon.social) --- config.py | 4 ++++ crawler/mastodon_crawler.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index a8d3be3..9ca2a0d 100644 --- a/config.py +++ b/config.py @@ -30,6 +30,10 @@ OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen3:8b-nothink") RSS_USER_AGENT = os.getenv("RSS_USER_AGENT", "vesti-rss/0.1 (+https://vesti.nixg.ru)") RSS_DEFAULT_TIMEOUT = float(os.getenv("RSS_DEFAULT_TIMEOUT", "20")) +# Mastodon-краулер: токен приложения (mastodon.social может требовать auth для +# /timelines/public; заголовок Authorization: Bearer ) +MASTODON_ACCESS_TOKEN = os.getenv("MASTODON_ACCESS_TOKEN", "") + # Направления (категории) DIRECTIONS = ["tech", "politics", "games", "electronics", "llm", "linux"] diff --git a/crawler/mastodon_crawler.py b/crawler/mastodon_crawler.py index 7ea28d8..4982f09 100644 --- a/crawler/mastodon_crawler.py +++ b/crawler/mastodon_crawler.py @@ -18,7 +18,7 @@ from urllib.parse import urlencode sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from config import RSS_DEFAULT_TIMEOUT, RSS_USER_AGENT, ensure_dirs +from config import MASTODON_ACCESS_TOKEN, RSS_DEFAULT_TIMEOUT, RSS_USER_AGENT, ensure_dirs from db.db import db from sources.sources import ( get_enabled_sources, get_source, load_sources_yaml, sync_sources_to_db, @@ -200,6 +200,10 @@ def run_source(source, dry_run=False): import httpx headers = {"User-Agent": RSS_USER_AGENT, "Accept": "application/json"} + if MASTODON_ACCESS_TOKEN: + # токен приложения (mastodon.social может требовать auth для + # /timelines/public); считается секретом — не логируется + headers["Authorization"] = f"Bearer {MASTODON_ACCESS_TOKEN}" client = httpx.Client(headers=headers, timeout=MASTODON_TIMEOUT, follow_redirects=True)