From b8dde3872d7d6c840a3628f55a28f00747bba838 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 5 Feb 2025 15:51:20 +0100 Subject: [PATCH] Continued: - rewrote many local variables in "row" list - need to convert SQL row into list() row(s0 - renamed variables 'r' is to short --- daemon.py | 24 ++++++++---------------- fba/http/federation.py | 32 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/daemon.py b/daemon.py index 53be826..f2eec11 100755 --- a/daemon.py +++ b/daemon.py @@ -215,25 +215,17 @@ LIMIT ?", [ amount ]) - blocklist = database.cursor.fetchall() + rows = database.cursor.fetchall() result = {} - for blocker, blocked, block_level, reason, first_seen, last_seen in blocklist: - if reason is not None and reason != "": - reason = reason.replace(",", " ").replace(" ", " ") - - entry = { - "blocker" : blocker, - "blocked" : blocked, - "reason" : reason, - "first_seen": first_seen, - "last_seen" : last_seen - } - - if block_level in result: - result[block_level].append(entry) + for row in list(rows): + if row["reason"] is not in [None, ""]: + row["reason"] = row["reason"].replace(",", " ").replace(" ", " ") + + if row["block_level"] in result: + result[row["block_level"]].append(row) else: - result[block_level] = [entry] + result[row["block_level"]] = [row] return result diff --git a/fba/http/federation.py b/fba/http/federation.py index 49fc55e..7a8b4ce 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -514,42 +514,42 @@ def find_domains(tag: bs4.element.Tag, domain_column: str = "dt", reason_column: reasons = element.find_next(reason_column).text.split(reason_text)[1].splitlines() logger.debug("domain='%s',reasons(%d)='%s'", domain, len(reasons), reasons) - reason = "" - for r in reasons: - logger.debug("r[%s]='%s'", type(r), r) - if r != "": - reason = r + found = "" + for reason in reasons: + logger.debug("reason[%s]='%s'", type(reason), reason) + if reason not in [None, ""]: + found = reason break - reason = tidyup.reason(reason) - logger.debug("domain='%s',reason='%s'", domain, reason) + found = tidyup.reason(found) + logger.debug("domain='%s',found='%s'", domain, found) - if not domain_helper.is_wanted(domain): - logger.debug("domain='%s' is blacklisted - SKIPPED!", domain) - continue - elif domain == "gab.com/.ai, develop.gab.com": + if domain == "gab.com/.ai, develop.gab.com": logger.debug("Multiple gab.com domains detected in one row") domains.append({ "domain": "gab.com", - "reason": reason, + "reason": found, }) domains.append({ "domain": "gab.ai", - "reason": reason, + "reason": found, }) domains.append({ "domain": "develop.gab.com", - "reason": reason, + "reason": found, }) continue elif not validators.domain(domain.split("/")[0], rfc_2782=True): logger.warning("domain='%s' is not a valid domain - SKIPPED!", domain) continue + elif not domain_helper.is_wanted(domain): + logger.debug("domain='%s' is not wanted - SKIPPED!", domain) + continue - logger.debug("Adding domain='%s',reason='%s' ...", domain, reason) + logger.debug("Adding domain='%s',found='%s' ...", domain, found) domains.append({ "domain": domain, - "reason": reason, + "reason": found, }) logger.debug("domains()=%d - EXIT!", len(domains)) -- 2.39.5