From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Thu, 31 Mar 2022 22:58:52 +0000 (+0200) Subject: cleaned code a bit more X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=39b07232bc949d1ce83026b44936fd93cbf16d4b;p=fba.git cleaned code a bit more --- diff --git a/fetch_blocks.py b/fetch_blocks.py index 15bb958..0522b85 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -45,9 +45,8 @@ c = conn.cursor() c.execute("select domain, software from instances where software in ('pleroma', 'mastodon')") -for instance in c.fetchall(): - if instance[1] == "pleroma": - blocker = instance[0] +for blocker, software in c.fetchall(): + if software == "pleroma": print(blocker) try: # Blocks @@ -83,19 +82,21 @@ for instance in c.fetchall(): conn.commit() except Exception as e: print("error:", e, blocker) - elif instance[1] == "mastodon": - blocker = instance[0] + elif software == "mastodon": print(blocker) try: c.execute("delete from blocks where blocker = ?", (blocker,)) json = get_mastodon_blocks(blocker) - for block_level in ["reject", "media_removal", "federated_timeline_removal"]: + for block_level in json: for blocked in json[block_level]: if blocked["domain"].count("*") > 1: + # instance is censored, check if domain of hash is known, if not, insert the hash c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, ?", (blocker, blocked["hash"], blocked["hash"], blocked['reason'], block_level)) else: + # instance is not censored c.execute("select domain from instances where domain = ?", (blocked["domain"],)) if c.fetchone() == None: + # if instance not known, add it c.execute("insert into instances select ?, ?, ?", (blocked["domain"], sha256(bytes(blocked["domain"], "utf-8")).hexdigest(), get_type(blocked["domain"]))) c.execute("insert into blocks select ?, ?, ?, ?", (blocker, blocked["domain"], blocked["reason"], block_level)) conn.commit()