]> git.mxchange.org Git - fba.git/commitdiff
added block fetching from pleroma instances
authorEnju Aihara <5-EnjuAihara@users.noreply.gitlab.varis.social>
Thu, 3 Mar 2022 23:41:18 +0000 (00:41 +0100)
committerEnju Aihara <5-EnjuAihara@users.noreply.gitlab.varis.social>
Thu, 3 Mar 2022 23:41:18 +0000 (00:41 +0100)
fetch_blocks.py [new file with mode: 0644]

diff --git a/fetch_blocks.py b/fetch_blocks.py
new file mode 100644 (file)
index 0000000..e590c24
--- /dev/null
@@ -0,0 +1,24 @@
+from requests import get
+from json import loads
+import sqlite3
+
+conn = sqlite3.connect("blocks.db")
+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}'")
+        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}'")
+            for blocked in json["metadata"]["federation"]["quarantined_instances"]:
+                c.execute(f"insert into blocks select '{blocker}', '{blocked}', '', 'quarantined_instances'")
+            conn.commit()
+        except:
+            pass
+
+conn.close()
\ No newline at end of file