added hash function
This commit is contained in:
parent
46cf65678e
commit
dcb862ed71
@ -39,6 +39,8 @@ def get_mastodon_blocks(domain: str) -> dict:
|
|||||||
"federated_timeline_removal": blocks["Limited servers"] + blocks["Silenced servers"],
|
"federated_timeline_removal": blocks["Limited servers"] + blocks["Silenced servers"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_hash(domain: str) -> str:
|
||||||
|
return sha256(domain.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
def get_type(domain: str) -> str:
|
def get_type(domain: str) -> str:
|
||||||
try:
|
try:
|
||||||
@ -73,7 +75,7 @@ for blocker, software in c.fetchall():
|
|||||||
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, sha256(bytes(blocked, "utf-8")).hexdigest(), 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, mrf))
|
||||||
# Quarantined Instances
|
# Quarantined Instances
|
||||||
if "quarantined_instances" in json["metadata"]["federation"]:
|
if "quarantined_instances" in json["metadata"]["federation"]:
|
||||||
@ -82,7 +84,7 @@ for blocker, software in c.fetchall():
|
|||||||
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, sha256(bytes(blocked, "utf-8")).hexdigest(), get_type(blocked)))
|
c.execute("insert into instances select ?, ?, ?", (blocked, get_hash(blocked), get_type(blocked)))
|
||||||
c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked))
|
c.execute("insert into blocks select ?, ?, '', 'quarantined_instances'", (blocker, blocked))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
# Reasons
|
# Reasons
|
||||||
@ -111,7 +113,7 @@ for blocker, software in c.fetchall():
|
|||||||
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
|
# 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"], get_hash(blocked["domain"]), 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()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user