]> git.mxchange.org Git - fba.git/commitdiff
cleaned code a bit more
authorEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Thu, 31 Mar 2022 22:58:52 +0000 (00:58 +0200)
committerEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Thu, 31 Mar 2022 22:58:52 +0000 (00:58 +0200)
fetch_blocks.py

index 15bb95838ae965e83426f5955f2ef2c4bc928c04..0522b851f5d6ddd4ae4bc44861215f7932b89f0d 100644 (file)
@@ -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()