From 724fc33f87c94e873c0337327b40f2cbb8358e60 Mon Sep 17 00:00:00 2001 From: Archos Date: Sat, 16 May 2026 22:02:43 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20podpora=20v=C3=ADce=20GTS=20token=C5=AF?= =?UTF-8?q?=20per-instance,=20p=C5=99id=C3=A1n=20shimon@gts.shimonh.eu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manual_accounts.csv | 1 + mastodon_cz_accounts.py | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/manual_accounts.csv b/manual_accounts.csv index 30e78f5..5a4148d 100644 --- a/manual_accounts.csv +++ b/manual_accounts.csv @@ -111,3 +111,4 @@ Oskar456@mastodon.social,true,false, jmlich@fosstodon.org,true,false, ronny@metalhead.club,true,false, vancura@mastodon.design,true,false, +shimon@gts.shimonh.eu,true,false, diff --git a/mastodon_cz_accounts.py b/mastodon_cz_accounts.py index fe442ce..efb6cb2 100644 --- a/mastodon_cz_accounts.py +++ b/mastodon_cz_accounts.py @@ -37,6 +37,17 @@ def _load_tokens(): break if val: tokens[key] = val.strip() + # per-instance GTS tokeny: GTS_TOKEN_ + for key, val in os.environ.items(): + if key.startswith("GTS_TOKEN_") and val: + tokens[key] = val.strip() + for line in env_lines: + line = line.strip() + if line.startswith("GTS_TOKEN_") and "=" in line: + key, val = line.split("=", 1) + key = key.strip() + if key not in tokens and val.strip(): + tokens[key] = val.strip() # fallback: raw token value (legacy .env bez klíče) if "MASTODON_TOKEN" not in tokens: for line in env_lines: @@ -47,8 +58,9 @@ def _load_tokens(): return tokens _TOKENS = _load_tokens() -MASTODON_TOKEN = _TOKENS.get("MASTODON_TOKEN") -GTS_TOKEN = _TOKENS.get("GTS_TOKEN") +MASTODON_TOKEN = _TOKENS.get("MASTODON_TOKEN") +GTS_TOKEN = _TOKENS.get("GTS_TOKEN") # legacy fallback +_GTS_INSTANCE_TOKENS = {k: v for k, v in _TOKENS.items() if k.startswith("GTS_TOKEN_")} _gts_cache: dict[str, bool] = {} @@ -62,8 +74,11 @@ def _is_gts(instance: str) -> bool: return result def _token_for(instance: str) -> str | None: - if GTS_TOKEN and _is_gts(instance): - return GTS_TOKEN + if _is_gts(instance): + key = "GTS_TOKEN_" + re.sub(r"[.\-]", "_", instance).upper() + token = _GTS_INSTANCE_TOKENS.get(key) or GTS_TOKEN + if token: + return token return MASTODON_TOKEN logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", datefmt="%H:%M:%S") @@ -177,11 +192,6 @@ def load_manual_accounts(seen_handles=None): url = f"https://{instance}/api/v1/accounts/lookup?acct={urllib.parse.quote(handle_part)}" token = _token_for(instance) acc = api_get(url, token=token) - if not acc or not isinstance(acc, dict): - log.debug(f" {instance}: is_gts={_is_gts(instance)}, gts_token={GTS_TOKEN is not None}") - if GTS_TOKEN and _is_gts(instance): - log.debug(f" {handle}: zkouším GTS_TOKEN") - acc = api_get(url, token=GTS_TOKEN) if not acc or not isinstance(acc, dict): log.warning(f" {handle}: lookup selhal") continue