]> git.mxchange.org Git - fba.git/blob - fetch_blocks.py
sorted instances by name
[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(f"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(f"insert into blocks select '{blocker}', '{blocked}', '', '{mrf}'")
18             for blocked in json["metadata"]["federation"]["quarantined_instances"]:
19                 c.execute(f"insert into blocks select '{blocker}', '{blocked}', '', 'quarantined_instances'")
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(f"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                 c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'reject'")
33             for blocked in json["media_removal"]:
34                 c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'media_removal'")
35             for blocked in json["federated_timeline_removal"]:
36                 c.execute(f"insert into blocks select '{blocker}', ifnull((select domain from instances where hash = '{blocked['hash']}'), '{blocked['hash']}'), '{blocked['reason']}', 'federated_timeline_removal'")
37             conn.commit()
38         except:
39             pass
40
41 conn.close()