From: Roland Häder Date: Mon, 22 May 2023 00:42:07 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5a8dd9c68ef847b5652c206f445785b5a6f9c5ed;p=fba.git Continued: - renamed variable - used more tidyup() --- diff --git a/api.py b/api.py index 7ad7c33..37b990d 100644 --- a/api.py +++ b/api.py @@ -50,7 +50,10 @@ def top(blocked: int = None, blockers: int = None, reference: int = None, softwa scoreboard = [] for domain, highscore in scores: - scoreboard.append({"domain": domain, "highscore": highscore}) + scoreboard.append({ + "domain" : domain, + "highscore": highscore + }) return scoreboard @@ -151,7 +154,14 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str block["first_added"] = datetime.utcfromtimestamp(block["first_added"]).strftime('%Y-%m-%d %H:%M') block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime('%Y-%m-%d %H:%M') - return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks, "reason": reason, "reverse": reverse, "info": info}) + return templates.TemplateResponse("index.html", { + "request": request, + "domain" : domain, + "blocks" : blocks, + "reason" : reason, + "reverse": reverse, + "info" : info + }) @app.get(fba.config["base_url"] + "/api/mutual") def mutual(domains: list[str] = Query()): diff --git a/fba.py b/fba.py index 5a5281c..8a89b86 100644 --- a/fba.py +++ b/fba.py @@ -357,16 +357,16 @@ def get_mastodon_blocks(domain: str) -> dict: for line in header.find_all_next("table")[0].find_all("tr")[1:]: blocks[header_text].append( { - "domain": line.find("span").text, - "hash": line.find("span")["title"][9:], - "reason": line.find_all("td")[1].text.strip(), + "domain": tidyup(line.find("span").text), + "hash" : tidyup(line.find("span")["title"][9:]), + "reason": tidyup(line.find_all("td")[1].text), } ) # NOISY-DEBUG: print("DEBUG: Returning blocks for domain:", domain) return { - "reject": blocks["Suspended servers"], - "media_removal": blocks["Filtered media"], + "reject" : blocks["Suspended servers"], + "media_removal" : blocks["Filtered media"], "followers_only": blocks["Limited servers"] + blocks["Silenced servers"], } @@ -392,8 +392,8 @@ def get_friendica_blocks(domain: str) -> dict: for line in blocklist.find("table").find_all("tr")[1:]: blocks.append({ - "domain": line.find_all("td")[0].text.strip(), - "reason": line.find_all("td")[1].text.strip() + "domain": tidyup(line.find_all("td")[0].text), + "reason": tidyup(line.find_all("td")[1].text) }) # NOISY-DEBUG: print("DEBUG: Returning blocks() for domain:", domain, len(blocks)) @@ -444,7 +444,7 @@ def get_misskey_blocks(domain: str) -> dict: if instance["isSuspended"]: blocks["suspended"].append( { - "domain": instance["host"], + "domain": tidyup(instance["host"]), # no reason field, nothing "reason": "" } @@ -491,7 +491,7 @@ def get_misskey_blocks(domain: str) -> dict: for instance in doc: if instance["isBlocked"]: blocks["blocked"].append({ - "domain": instance["host"], + "domain": tidyup(instance["host"]), "reason": "" }) @@ -516,23 +516,26 @@ def get_misskey_blocks(domain: str) -> dict: print("WARNING: API request failed for domain:", domain) return {} -def tidyup(domain: str) -> str: +def tidyup(string: str) -> str: + # NOISY-DEBUG: print("DEBUG: BEFORE string:", string) + # some retards put their blocks in variable case - domain = domain.lower() + string = string.lower().strip() # other retards put the port - domain = re.sub("\:\d+$", "", domain) + string = re.sub("\:\d+$", "", string) # bigger retards put the schema in their blocklist, sometimes even without slashes - domain = re.sub("^https?\:(\/*)", "", domain) + string = re.sub("^https?\:(\/*)", "", string) # and trailing slash - domain = re.sub("\/$", "", domain) + string = re.sub("\/$", "", string) # and the @ - domain = re.sub("^\@", "", domain) + string = re.sub("^\@", "", string) # the biggest retards of them all try to block individual users - domain = re.sub("(.+)\@", "", domain) + string = re.sub("(.+)\@", "", string) - return domain + # NOISY-DEBUG: print("DEBUG: AFTER string:", string) + return string diff --git a/fetch_blocks.py b/fetch_blocks.py index 57a53a8..704176e 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -268,13 +268,15 @@ for blocker, software in fba.cursor.fetchall(): fba.connection.commit() except Exception as e: print("error:", e, blocker, software) - elif software == "friendica" or software == "misskey": + elif software == "friendica" or software == "misskey" or software == "bookwyrm": print("INFO: blocker:", blocker) try: if software == "friendica": json = fba.get_friendica_blocks(blocker) elif software == "misskey": json = fba.get_misskey_blocks(blocker) + elif software == "bookwyrm": + json = fba.get_bookwyrm_blocks(blocker) for block_level, blocks in json.items(): # NOISY-DEBUG: print("DEBUG: blocker,block_level,blocks():", blocker, block_level, len(blocks))