]> git.mxchange.org Git - fba.git/blob - fetch_blocks.py
c94d7d7fb3fcf3be930b8762ce5604e6eab422e2
[fba.git] / fetch_blocks.py
1 from requests import get
2 from json import loads
3 import sqlite3
4
5 conn = sqlite3.connect("blocks.db")
6 c = conn.cursor()
7
8 with open("pleroma_instances.txt", "r") as f:
9     while blocker := f.readline().strip():
10         print(blocker)
11         c.execute("delete from blocks where blocker = ?", (blocker,))
12         conn.commit()
13         try:
14             json = loads(get(f"https://{blocker}/nodeinfo/2.1.json").text)
15             for mrf in json["metadata"]["federation"]["mrf_simple"]:
16                 for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]:
17                     c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, mrf))
18             for blocked in json["metadata"]["federation"]["quarantined_instances"]:
19                 c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked))
20             conn.commit()
21         except:
22             pass
23
24 with open("mastodon_instances.txt", "r") as f:
25     while blocker := f.readline().strip():
26         print(blocker)
27         c.execute("delete from blocks where blocker = ?", (blocker,))
28         conn.commit()
29         try:
30             json = loads(get(f"http://127.0.0.1:8069/{blocker}").text)
31             for blocked in json["reject"]:
32                 if blocked["domain"].count("*") > 1:
33                     c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'reject'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
34                 else:
35                     c.execute("insert into blocks select ?, ?, ?, 'reject'", (blocker, blocked["domain"], blocked["reason"]))
36             for blocked in json["media_removal"]:
37                 if blocked["domain"].count("*") > 1:
38                     c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'media_removal'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
39                 else:
40                     c.execute("insert into blocks select ?, ?, ?, 'media_removal'", (blocker, blocked["domain"], blocked["reason"]))
41             for blocked in json["federated_timeline_removal"]:
42                 if blocked["domain"].count("*") > 1:
43                     c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, 'federated_timeline_removal'", (blocker, blocked["hash"], blocked["hash"], blocked['reason']))
44                 else:
45                     c.execute("insert into blocks select ?, ?, ?, 'federated_timeline_removal'", (blocker, blocked["domain"], blocked["reason"]))
46             conn.commit()
47         except:
48             pass
49
50 conn.close()