From 5ba472f87a2c10ce7de93193820c1ea5905c5762 Mon Sep 17 00:00:00 2001 From: Archos Date: Sun, 3 May 2026 08:03:02 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20podpora=20GTS=20instanc=C3=AD=20s=20GTS?= =?UTF-8?q?=5FTOKEN,=20p=C5=99id=C3=A1n=20arch@gts.arch-linux.cz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manual_accounts.csv | 2 +- mastodon_cz_accounts.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/manual_accounts.csv b/manual_accounts.csv index 3518214..fc6533c 100644 --- a/manual_accounts.csv +++ b/manual_accounts.csv @@ -96,7 +96,7 @@ nacelnik01@mamutovo.cz,true,false, sledge@mastodonczech.cz,true,false, tensob_@mastodonczech.cz,true,false archos@mamutovo.cz,true,false, -arch@arch-linux.cz,true,false, +arch@gts.arch-linux.cz,true,false, electric@vaclavpasek.cz,true,false, adamhavelka@mastodon.prorocketeers.com,true,false, Kipe@mastodon.social,true,false, diff --git a/mastodon_cz_accounts.py b/mastodon_cz_accounts.py index b7f96e4..fe442ce 100644 --- a/mastodon_cz_accounts.py +++ b/mastodon_cz_accounts.py @@ -50,9 +50,19 @@ _TOKENS = _load_tokens() MASTODON_TOKEN = _TOKENS.get("MASTODON_TOKEN") GTS_TOKEN = _TOKENS.get("GTS_TOKEN") +_gts_cache: dict[str, bool] = {} + +def _is_gts(instance: str) -> bool: + if instance in _gts_cache: + return _gts_cache[instance] + info = api_get(f"https://{instance}/api/v1/instance") + version = (info or {}).get("version", "") if isinstance(info, dict) else "" + result = "git" in version or version.startswith("0.") + _gts_cache[instance] = result + return result + def _token_for(instance: str) -> str | None: - """Vrátí GTS_TOKEN pro GoToSocial instance (obsahují 'gts.' v doméně), jinak MASTODON_TOKEN.""" - if GTS_TOKEN and "gts." in instance: + if GTS_TOKEN and _is_gts(instance): return GTS_TOKEN return MASTODON_TOKEN @@ -167,6 +177,11 @@ 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