]> git.mxchange.org Git - fba.git/commitdiff
use domain from mastodon instances if not censored
authorEnju Aihara <5-EnjuAihara@users.noreply.gitlab.varis.social>
Fri, 4 Mar 2022 23:15:08 +0000 (00:15 +0100)
committerEnju Aihara <5-EnjuAihara@users.noreply.gitlab.varis.social>
Fri, 4 Mar 2022 23:15:08 +0000 (00:15 +0100)
fetch_blocks.py

index dbf53a92110505a4d24a02ddc1582f7f6b22d0d8..c94d7d7fb3fcf3be930b8762ce5604e6eab422e2 100644 (file)
@@ -8,15 +8,15 @@ c = conn.cursor()
 with open("pleroma_instances.txt", "r") as f:
     while blocker := f.readline().strip():
         print(blocker)
-        c.execute(f"delete from blocks where blocker = '{blocker}'")
+        c.execute("delete from blocks where blocker = ?", (blocker,))
         conn.commit()
         try:
             json = loads(get(f"https://{blocker}/nodeinfo/2.1.json").text)
             for mrf in json["metadata"]["federation"]["mrf_simple"]:
                 for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]:
-                    c.execute(f"insert into blocks select '{blocker}', '{blocked}', '', '{mrf}'")
+                    c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, mrf))
             for blocked in json["metadata"]["federation"]["quarantined_instances"]:
-                c.execute(f"insert into blocks select '{blocker}', '{blocked}', '', 'quarantined_instances'")
+                c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked))
             conn.commit()
         except:
             pass
@@ -24,16 +24,25 @@ with open("pleroma_instances.txt", "r") as f:
 with open("mastodon_instances.txt", "r") as f:
     while blocker := f.readline().strip():
         print(blocker)
-        c.execute(f"delete from blocks where blocker = '{blocker}'")
+        c.execute("delete from blocks where blocker = ?", (blocker,))
         conn.commit()
         try:
             json = loads(get(f"http://127.0.0.1:8069/{blocker}").text)
             for blocked in json["reject"]:
-                c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'reject'")
+                if blocked["domain"].count("*") > 1:
+                    c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'reject'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
+                else:
+                    c.execute("insert into blocks select ?, ?, ?, 'reject'", (blocker, blocked["domain"], blocked["reason"]))
             for blocked in json["media_removal"]:
-                c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'media_removal'")
+                if blocked["domain"].count("*") > 1:
+                    c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'media_removal'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
+                else:
+                    c.execute("insert into blocks select ?, ?, ?, 'media_removal'", (blocker, blocked["domain"], blocked["reason"]))
             for blocked in json["federated_timeline_removal"]:
-                c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'federated_timeline_removal'")
+                if blocked["domain"].count("*") > 1:
+                    c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'federated_timeline_removal'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
+                else:
+                    c.execute("insert into blocks select ?, ?, ?, 'federated_timeline_removal'", (blocker, blocked["domain"], blocked["reason"]))
             conn.commit()
         except:
             pass