Follow

elilla’s ditzy script for mass blocking, now with fediblock.org support 

I am a very dirty girl but this will inject the @fediblock_archive blocklist directly into your database. not guaranteed to work in future versions of either software (or at all), but might be useful in dealing with the current wave of bad actors. won’t work on vanilla masto unless it uses the exact same database format (no idea if they do).

 #!/usr/bin/env python3
import sys
import psycopg2
import urllib.request
import json
from datetime import datetime
from typing import List

# expects working pgident auth. edit parameters to your own:
database='mastodon_production'
dbuser='mastodon'

URL = 'https://fediblock.org/api/v1/list'

BLOCKSQL = """
INSERT INTO domain_blocks (
severity,
reject_media,
reject_reports,

domain,
created_at,
updated_at,
public_comment
) VALUES (1, true, true, %s, %s, %s, %s )
;"""


conn = psycopg2.connect(database=database, user=dbuser)
conn.autocommit = True
CUR = conn.cursor()

def begone(
domain: str,
description: str = '',
report_time: str = '',
tags: List[str] = [],
):
try:
public_comment = "From %s:\n%s" % (URL, description)
if tags:
public_comment += "\n\nTags: " + ', '.join(tags)
created_at = report_time
updated_at = datetime.now()

CUR.execute(BLOCKSQL, (domain, created_at, updated_at, public_comment))
except psycopg2.IntegrityError:
print("Skipping %s (already blocked?)" % domain)

def parse_blockurl(url: str):
with urllib.request.urlopen(url) as req:
block = json.loads(req.read().decode())
# timezone unspecified in the API, who knows. use naïve obj.
block['report_time'] = datetime.strptime(block['report_time'],
'%Y-%m-%dT%H:%M:%S')
begone(*(block[key] for key in ('instance', 'description', 'report_time', 'tags')))

with urllib.request.urlopen("https://fediblock.org/api/v1/list") as req:
blocklist = json.loads(req.read().decode())
for item in blocklist:
parse_blockurl(item['url'])

re: elilla’s ditzy script for mass blocking, now with fediblock.org support 

oh and it's idempotent so one could put it on cron o/

elilla’s ditzy script for mass blocking, now with fediblock.org support 

@elilla *screams*
I want a way to block domains via api so badly.

thank you for this :blobheart:

personal harassment, freeze peach 

@compufox I wanted that mostly for convenience and time-saving, but now I want an API to implement automated shareable blocklist subscriptions and I’d be willing to work on that myself, specifically to spite free speech advocates who insist in spamming me about the dangers of political censorship _while_ I’m being dogpiled, screenshoted, defamed, and thrown slurs at by fash instances, terf servers and kiwifarms infiltrators.

re: elilla’s ditzy script for mass blocking, now with fediblock.org support 

@elilla report_time is UTC. It seems we forgot to add a “Z”. :blobfacepalm:

elilla’s ditzy script for mass blocking, now with fediblock.org support 

@elilla

@fediblock_archive

This is awesome and clever and I love it.

I'm also terrified of scripts that pipe whatever magic string happens to come back over http straight into a database query string.

This is clearly risky, but you clearly can't hear me over the sound of how cool you are. 🤣

Sign in to participate in the conversation
transmom.love

Personal server for trans moms <3