very slightly improve the horrid code quality

This commit is contained in:
Tove 2024-12-08 12:26:53 +01:00
parent 70b5a08c62
commit 4d4017fb8e

View file

@ -116,65 +116,44 @@ def get_friendica_blocks(domain: str) -> dict:
"reject": blocks
}
def get_pisskey_blocks(domain: str) -> dict:
def get_anykey_blocks(domain: str) -> dict:
blocks = {
"suspended": [],
"blocked": []
}
try:
counter = 0
step = 99
while True:
# iterating through all "suspended" (follow-only in its terminology) instances page-by-page, since that troonware doesn't support sending them all at once
try:
if counter == 0:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: raise
else:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step,"offset":counter-1}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: raise
for instance in doc:
# just in case
if instance["isSuspended"]:
blocks["suspended"].append(
{
"domain": instance["host"],
# no reason field, nothing
"reason": ""
}
)
counter = counter + step
# for now I'll assume no one in their right mind would block more than 2500 instances
# greetings to abstroonztaube
if counter > 2500:
break
except:
counter = 0
break
while True:
# same shit, different asshole ("blocked" aka full suspend)
try:
if counter == 0:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"blocked":True,"limit":step}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: raise
else:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"blocked":True,"limit":step,"offset":counter-1}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: raise
for instance in doc:
if instance["isBlocked"]:
blocks["blocked"].append(
{
"domain": instance["host"],
"reason": ""
}
)
counter = counter + step
if counter > 2500:
break
except:
counter = 0
counter = 0
step = 99
while True:
# iterating through all "suspended" (follow-only in its terminology) instances page-by-page
try:
if counter == 0:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: break
else:
doc = post(f"https://{domain}/api/federation/instances", data=dumps({"sort":"+caughtAt","host":None,"suspended":True,"limit":step,"offset":counter-1}), headers={**headers, **{"Content-Type": "application/json"}}, timeout=5, allow_redirects=False).json()
if doc == []: break
for instance in doc:
# just in case
if instance["isSuspended"]:
blocks["suspended"].append(
{
"domain": instance["host"],
# no reason field, nothing
"reason": ""
}
)
if instance["isBlocked"]:
blocks["blocked"].append(
{
"domain": instance["host"],
"reason": ""
}
)
counter = counter + step
# for now I'll assume no one in their right mind would block more than 2500 instances
# greetings to absturztau.be
if counter > 2500:
break
return {
@ -449,7 +428,7 @@ for blocker, software in c.fetchall():
if software == "friendica":
json = get_friendica_blocks(blocker)
elif software == "misskey":
json = get_pisskey_blocks(blocker)
json = get_anykey_blocks(blocker)
for block_level, blocks in json.items():
for instance in blocks:
blocked, reason = instance.values()