From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Sat, 9 Apr 2022 15:57:03 +0000 (+0200) Subject: refactored the pleroma part X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=65ef38213b1b0bacb393b01ddce7bda2358a2d15;p=fba.git refactored the pleroma part --- diff --git a/fetch_blocks.py b/fetch_blocks.py index 6da1089..187d23e 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -67,34 +67,22 @@ for blocker, software in c.fetchall(): try: # Blocks c.execute("delete from blocks where blocker = ?", (blocker,)) - json = get(f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5).json() - if "mrf_simple" in json["metadata"]["federation"]: - for mrf in json["metadata"]["federation"]["mrf_simple"]: - for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]: + federation = get(f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5).json()["metadata"]["federation"] + if "mrf_simple" in federation: + for block_level, blocks in (federation["mrf_simple"] | {"quarantined_instances": federation["quarantined_instances"]}).items(): + for blocked in blocks: if blocked == "": continue c.execute("select domain from instances where domain = ?", (blocked,)) if c.fetchone() == None: c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked))) - c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, mrf)) - # Quarantined Instances - if "quarantined_instances" in json["metadata"]["federation"]: - for blocked in json["metadata"]["federation"]["quarantined_instances"]: - if blocked == "": - continue - c.execute("select domain from instances where domain = ?", (blocked,)) - if c.fetchone() == None: - c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked))) - c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked)) + c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, block_level)) conn.commit() # Reasons - if "mrf_simple_info" in json["metadata"]["federation"]: - for mrf in json["metadata"]["federation"]["mrf_simple_info"]: - for blocked in json["metadata"]["federation"]["mrf_simple_info"][mrf]: - c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ?", (json["metadata"]["federation"]["mrf_simple_info"][mrf][blocked]["reason"], blocker, blocked, mrf)) - if "quarantined_instances_info" in json["metadata"]["federation"]: - for blocked in json["metadata"]["federation"]["quarantined_instances_info"]["quarantined_instances"]: - c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = 'quarantined_instances'", (json["metadata"]["federation"]["quarantined_instances_info"]["quarantined_instances"][blocked]["reason"], blocker, blocked)) + if "mrf_simple_info" in federation: + for block_level, info in (federation["mrf_simple_info"] | federation["quarantined_instances_info"] if "quarantined_instances_info" in federation else {}).items(): + for blocked, reason in info.items(): + c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ?", (reason["reason"], blocker, blocked, block_level)) conn.commit() except Exception as e: print("error:", e, blocker)