cleaned code a bit more
This commit is contained in:
parent
012fd3ceef
commit
39b07232bc
@ -45,9 +45,8 @@ c = conn.cursor()
|
|||||||
|
|
||||||
c.execute("select domain, software from instances where software in ('pleroma', 'mastodon')")
|
c.execute("select domain, software from instances where software in ('pleroma', 'mastodon')")
|
||||||
|
|
||||||
for instance in c.fetchall():
|
for blocker, software in c.fetchall():
|
||||||
if instance[1] == "pleroma":
|
if software == "pleroma":
|
||||||
blocker = instance[0]
|
|
||||||
print(blocker)
|
print(blocker)
|
||||||
try:
|
try:
|
||||||
# Blocks
|
# Blocks
|
||||||
@ -83,19 +82,21 @@ for instance in c.fetchall():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error:", e, blocker)
|
print("error:", e, blocker)
|
||||||
elif instance[1] == "mastodon":
|
elif software == "mastodon":
|
||||||
blocker = instance[0]
|
|
||||||
print(blocker)
|
print(blocker)
|
||||||
try:
|
try:
|
||||||
c.execute("delete from blocks where blocker = ?", (blocker,))
|
c.execute("delete from blocks where blocker = ?", (blocker,))
|
||||||
json = get_mastodon_blocks(blocker)
|
json = get_mastodon_blocks(blocker)
|
||||||
for block_level in ["reject", "media_removal", "federated_timeline_removal"]:
|
for block_level in json:
|
||||||
for blocked in json[block_level]:
|
for blocked in json[block_level]:
|
||||||
if blocked["domain"].count("*") > 1:
|
if blocked["domain"].count("*") > 1:
|
||||||
|
# instance is censored, check if domain of hash is known, if not, insert the hash
|
||||||
c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, ?", (blocker, blocked["hash"], blocked["hash"], blocked['reason'], block_level))
|
c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, ?", (blocker, blocked["hash"], blocked["hash"], blocked['reason'], block_level))
|
||||||
else:
|
else:
|
||||||
|
# instance is not censored
|
||||||
c.execute("select domain from instances where domain = ?", (blocked["domain"],))
|
c.execute("select domain from instances where domain = ?", (blocked["domain"],))
|
||||||
if c.fetchone() == None:
|
if c.fetchone() == None:
|
||||||
|
# if instance not known, add it
|
||||||
c.execute("insert into instances select ?, ?, ?", (blocked["domain"], sha256(bytes(blocked["domain"], "utf-8")).hexdigest(), get_type(blocked["domain"])))
|
c.execute("insert into instances select ?, ?, ?", (blocked["domain"], sha256(bytes(blocked["domain"], "utf-8")).hexdigest(), get_type(blocked["domain"])))
|
||||||
c.execute("insert into blocks select ?, ?, ?, ?", (blocker, blocked["domain"], blocked["reason"], block_level))
|
c.execute("insert into blocks select ?, ?, ?, ?", (blocker, blocked["domain"], blocked["reason"], block_level))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user