refactored the pleroma part
This commit is contained in:
parent
1d2079c3ae
commit
65ef38213b
@ -67,34 +67,22 @@ for blocker, software in c.fetchall():
|
|||||||
try:
|
try:
|
||||||
# Blocks
|
# Blocks
|
||||||
c.execute("delete from blocks where blocker = ?", (blocker,))
|
c.execute("delete from blocks where blocker = ?", (blocker,))
|
||||||
json = get(f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5).json()
|
federation = get(f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5).json()["metadata"]["federation"]
|
||||||
if "mrf_simple" in json["metadata"]["federation"]:
|
if "mrf_simple" in federation:
|
||||||
for mrf in json["metadata"]["federation"]["mrf_simple"]:
|
for block_level, blocks in (federation["mrf_simple"] | {"quarantined_instances": federation["quarantined_instances"]}).items():
|
||||||
for blocked in json["metadata"]["federation"]["mrf_simple"][mrf]:
|
for blocked in blocks:
|
||||||
if blocked == "":
|
if blocked == "":
|
||||||
continue
|
continue
|
||||||
c.execute("select domain from instances where domain = ?", (blocked,))
|
c.execute("select domain from instances where domain = ?", (blocked,))
|
||||||
if c.fetchone() == None:
|
if c.fetchone() == None:
|
||||||
c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked)))
|
c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked)))
|
||||||
c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, mrf))
|
c.execute("insert into blocks select ?, ?, '', ?", (blocker, blocked, block_level))
|
||||||
# Quarantined Instances
|
|
||||||
if "quarantined_instances" in json["metadata"]["federation"]:
|
|
||||||
for blocked in json["metadata"]["federation"]["quarantined_instances"]:
|
|
||||||
if blocked == "":
|
|
||||||
continue
|
|
||||||
c.execute("select domain from instances where domain = ?", (blocked,))
|
|
||||||
if c.fetchone() == None:
|
|
||||||
c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked)))
|
|
||||||
c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked))
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
# Reasons
|
# Reasons
|
||||||
if "mrf_simple_info" in json["metadata"]["federation"]:
|
if "mrf_simple_info" in federation:
|
||||||
for mrf in json["metadata"]["federation"]["mrf_simple_info"]:
|
for block_level, info in (federation["mrf_simple_info"] | federation["quarantined_instances_info"] if "quarantined_instances_info" in federation else {}).items():
|
||||||
for blocked in json["metadata"]["federation"]["mrf_simple_info"][mrf]:
|
for blocked, reason in info.items():
|
||||||
c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ?", (json["metadata"]["federation"]["mrf_simple_info"][mrf][blocked]["reason"], blocker, blocked, mrf))
|
c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ?", (reason["reason"], blocker, blocked, block_level))
|
||||||
if "quarantined_instances_info" in json["metadata"]["federation"]:
|
|
||||||
for blocked in json["metadata"]["federation"]["quarantined_instances_info"]["quarantined_instances"]:
|
|
||||||
c.execute("update blocks set reason = ? where blocker = ? and blocked = ? and block_level = 'quarantined_instances'", (json["metadata"]["federation"]["quarantined_instances_info"]["quarantined_instances"][blocked]["reason"], blocker, blocked))
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error:", e, blocker)
|
print("error:", e, blocker)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user