]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 00:42:07 +0000 (02:42 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 00:44:55 +0000 (02:44 +0200)
- renamed variable
- used more tidyup()

api.py
fba.py
fetch_blocks.py

diff --git a/api.py b/api.py
index 7ad7c336489f5ae36850a3c3d17ab89714ac3171..37b990d8851a4eeca124f2396cf95cf153d8514a 100644 (file)
--- a/api.py
+++ b/api.py
@@ -50,7 +50,10 @@ def top(blocked: int = None, blockers: int = None, reference: int = None, softwa
     scoreboard = []
 
     for domain, highscore in scores:
-        scoreboard.append({"domain": domain, "highscore": highscore})
+        scoreboard.append({
+            "domain"   : domain,
+            "highscore": highscore
+        })
 
     return scoreboard
 
@@ -151,7 +154,14 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str
                 block["first_added"] = datetime.utcfromtimestamp(block["first_added"]).strftime('%Y-%m-%d %H:%M')
                 block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime('%Y-%m-%d %H:%M')
 
-    return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks, "reason": reason, "reverse": reverse, "info": info})
+    return templates.TemplateResponse("index.html", {
+        "request": request,
+        "domain" : domain,
+        "blocks" : blocks,
+        "reason" : reason,
+        "reverse": reverse,
+        "info"   : info
+    })
 
 @app.get(fba.config["base_url"] + "/api/mutual")
 def mutual(domains: list[str] = Query()):
diff --git a/fba.py b/fba.py
index 5a5281c5b0442888f90a7cfca195ae4825b46f1a..8a89b864b3ea54c5bab684ecc21313b7ac82cfa0 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -357,16 +357,16 @@ def get_mastodon_blocks(domain: str) -> dict:
             for line in header.find_all_next("table")[0].find_all("tr")[1:]:
                 blocks[header_text].append(
                     {
-                        "domain": line.find("span").text,
-                        "hash": line.find("span")["title"][9:],
-                        "reason": line.find_all("td")[1].text.strip(),
+                        "domain": tidyup(line.find("span").text),
+                        "hash"  : tidyup(line.find("span")["title"][9:]),
+                        "reason": tidyup(line.find_all("td")[1].text),
                     }
                 )
 
     # NOISY-DEBUG: print("DEBUG: Returning blocks for domain:", domain)
     return {
-        "reject": blocks["Suspended servers"],
-        "media_removal": blocks["Filtered media"],
+        "reject"        : blocks["Suspended servers"],
+        "media_removal" : blocks["Filtered media"],
         "followers_only": blocks["Limited servers"] + blocks["Silenced servers"],
     }
 
@@ -392,8 +392,8 @@ def get_friendica_blocks(domain: str) -> dict:
 
     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()
+            "domain": tidyup(line.find_all("td")[0].text),
+            "reason": tidyup(line.find_all("td")[1].text)
         })
 
     # NOISY-DEBUG: print("DEBUG: Returning blocks() for domain:", domain, len(blocks))
@@ -444,7 +444,7 @@ def get_misskey_blocks(domain: str) -> dict:
                     if instance["isSuspended"]:
                         blocks["suspended"].append(
                             {
-                                "domain": instance["host"],
+                                "domain": tidyup(instance["host"]),
                                 # no reason field, nothing
                                 "reason": ""
                             }
@@ -491,7 +491,7 @@ def get_misskey_blocks(domain: str) -> dict:
                 for instance in doc:
                     if instance["isBlocked"]:
                         blocks["blocked"].append({
-                            "domain": instance["host"],
+                            "domain": tidyup(instance["host"]),
                             "reason": ""
                         })
 
@@ -516,23 +516,26 @@ def get_misskey_blocks(domain: str) -> dict:
         print("WARNING: API request failed for domain:", domain)
         return {}
 
-def tidyup(domain: str) -> str:
+def tidyup(string: str) -> str:
+    # NOISY-DEBUG: print("DEBUG: BEFORE string:", string)
+
     # some retards put their blocks in variable case
-    domain = domain.lower()
+    string = string.lower().strip()
 
     # other retards put the port
-    domain = re.sub("\:\d+$", "", domain)
+    string = re.sub("\:\d+$", "", string)
 
     # bigger retards put the schema in their blocklist, sometimes even without slashes
-    domain = re.sub("^https?\:(\/*)", "", domain)
+    string = re.sub("^https?\:(\/*)", "", string)
 
     # and trailing slash
-    domain = re.sub("\/$", "", domain)
+    string = re.sub("\/$", "", string)
 
     # and the @
-    domain = re.sub("^\@", "", domain)
+    string = re.sub("^\@", "", string)
 
     # the biggest retards of them all try to block individual users
-    domain = re.sub("(.+)\@", "", domain)
+    string = re.sub("(.+)\@", "", string)
 
-    return domain
+    # NOISY-DEBUG: print("DEBUG: AFTER string:", string)
+    return string
index 57a53a8cd299b52a646ad85a2c810e2bcde150ad..704176e5dc7228b36c8fc5f0762fe7aee5da9d8f 100644 (file)
@@ -268,13 +268,15 @@ for blocker, software in fba.cursor.fetchall():
             fba.connection.commit()
         except Exception as e:
             print("error:", e, blocker, software)
-    elif software == "friendica" or software == "misskey":
+    elif software == "friendica" or software == "misskey" or software == "bookwyrm":
         print("INFO: blocker:", blocker)
         try:
             if software == "friendica":
                 json = fba.get_friendica_blocks(blocker)
             elif software == "misskey":
                 json = fba.get_misskey_blocks(blocker)
+            elif software == "bookwyrm":
+                json = fba.get_bookwyrm_blocks(blocker)
 
             for block_level, blocks in json.items():
                 # NOISY-DEBUG: print("DEBUG: blocker,block_level,blocks():", blocker, block_level, len(blocks))