From 03358a3c6ef9fc3e16219c70d97e931e975a3426 Mon Sep 17 00:00:00 2001 From: Mint <> Date: Fri, 21 Oct 2022 01:02:07 +0300 Subject: [PATCH] New Masto API support --- fetch_blocks.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/fetch_blocks.py b/fetch_blocks.py index 15d1a6d..ccd89cb 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -58,7 +58,7 @@ def get_mastodon_blocks(domain: str) -> dict: return { "reject": blocks["Suspended servers"], "media_removal": blocks["Filtered media"], - "federated_timeline_removal": blocks["Limited servers"] + "followers_only": blocks["Limited servers"] + blocks["Silenced servers"], } @@ -273,7 +273,30 @@ for blocker, software in c.fetchall(): elif software == "mastodon": print(blocker) try: - json = get_mastodon_blocks(blocker) + # json endpoint for newer mastodongs + try: + json = { + "reject": [], + "media_removal": [], + "followers_only": [], + "report_removal": [] + } + blocks = get( + f"https://{blocker}/api/v1/instance/domain_blocks", headers=headers, timeout=5 + ).json() + for block in blocks: + entry = {'domain': block['domain'], 'hash': block['digest'], 'reason': block['comment']} + if block['severity'] == 'suspend': + json['reject'].append(entry) + elif block['severity'] == 'silence': + json['followers_only'].append(entry) + elif block['severity'] == 'reject_media': + json['media_removal'].append(entry) + elif block['severity'] == 'reject_reports': + json['report_removal'].append(entry) + except: + json = get_mastodon_blocks(blocker) + for block_level, blocks in json.items(): for instance in blocks: blocked, blocked_hash, reason = instance.values() -- 2.39.5