refactored the mastodon part
This commit is contained in:
parent
65ef38213b
commit
7941765b04
@ -91,18 +91,25 @@ for blocker, software in c.fetchall():
|
|||||||
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 json:
|
for block_level, blocks in json.items():
|
||||||
for blocked in json[block_level]:
|
for instance in blocks:
|
||||||
if blocked["domain"].count("*") > 1:
|
blocked, blocked_hash, reason = instance.values()
|
||||||
# instance is censored, check if domain of hash is known, if not, insert the hash
|
if blocked.count("*") <= 1:
|
||||||
c.execute("insert into blocks select ?, ifnull((select domain from instances where hash = ?), ?), ?, ?", (blocker, blocked["hash"], blocked["hash"], blocked['reason'], block_level))
|
c.execute("select hash from instances where hash = ?", (blocked_hash,))
|
||||||
else:
|
|
||||||
# instance is not censored
|
|
||||||
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(
|
||||||
c.execute("insert into instances select ?, ?, ?", (blocked["domain"], get_hash(blocked["domain"]), get_type(blocked["domain"])))
|
"insert into instances select ?, ?, ?",
|
||||||
c.execute("insert into blocks select ?, ?, ?, ?", (blocker, blocked["domain"], blocked["reason"], block_level))
|
(blocked, get_hash(blocked), get_type(blocked)),
|
||||||
|
)
|
||||||
|
c.execute(
|
||||||
|
"insert into blocks select ?, ?, ?, ?",
|
||||||
|
(
|
||||||
|
blocker,
|
||||||
|
blocked if blocked.count("*") <= 1 else blocked_hash,
|
||||||
|
reason,
|
||||||
|
block_level,
|
||||||
|
),
|
||||||
|
)
|
||||||
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