Friendica support & possible fix for duplicate values when parsing Masto
This commit is contained in:
parent
ffb8c56fd9
commit
6e72f19967
@ -56,6 +56,29 @@ def get_mastodon_blocks(domain: str) -> dict:
|
|||||||
+ blocks["Silenced servers"],
|
+ blocks["Silenced servers"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_friendica_blocks(domain: str) -> dict:
|
||||||
|
blocks = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
doc = BeautifulSoup(
|
||||||
|
get(f"https://{domain}/friendica", headers=headers, timeout=5).text,
|
||||||
|
"html.parser",
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
blocklist = doc.find(id="about_blocklist")
|
||||||
|
for line in blocklist.find("table").find_all("tr")[1:]:
|
||||||
|
blocks.append(
|
||||||
|
{
|
||||||
|
"domain": line.find_all("td")[0].text.strip(),
|
||||||
|
"reason": line.find_all("td")[1].text.strip()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"reject": blocks
|
||||||
|
}
|
||||||
|
|
||||||
def get_hash(domain: str) -> str:
|
def get_hash(domain: str) -> str:
|
||||||
return sha256(domain.encode("utf-8")).hexdigest()
|
return sha256(domain.encode("utf-8")).hexdigest()
|
||||||
@ -164,7 +187,7 @@ for blocker, software in c.fetchall():
|
|||||||
)
|
)
|
||||||
c.execute(
|
c.execute(
|
||||||
"select * from blocks where blocker = ? and blocked = ? and block_level = ?",
|
"select * from blocks where blocker = ? and blocked = ? and block_level = ?",
|
||||||
(blocker, blocked, block_level),
|
(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level),
|
||||||
)
|
)
|
||||||
if c.fetchone() == None:
|
if c.fetchone() == None:
|
||||||
c.execute(
|
c.execute(
|
||||||
@ -179,4 +202,38 @@ for blocker, software in c.fetchall():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error:", e, blocker)
|
print("error:", e, blocker)
|
||||||
|
elif software == "friendica"
|
||||||
|
print(blocker)
|
||||||
|
try:
|
||||||
|
json = get_friendica_blocks(blocker)
|
||||||
|
for blocks in json.items():
|
||||||
|
for instance in blocks:
|
||||||
|
blocked, reason = instance.values()
|
||||||
|
blocked == blocked.lower()
|
||||||
|
blocker == blocker.lower()
|
||||||
|
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(
|
||||||
|
"select * from blocks where blocker = ? and blocked = ?",
|
||||||
|
(blocker, blocked),
|
||||||
|
)
|
||||||
|
if c.fetchone() == None:
|
||||||
|
c.execute(
|
||||||
|
"insert into blocks select ?, ?, ?, ?",
|
||||||
|
(
|
||||||
|
blocker,
|
||||||
|
blocked,
|
||||||
|
reason,
|
||||||
|
"reject",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
except Exception as e:
|
||||||
|
print("error:", e, blocker)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user