]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 20 May 2023 07:39:57 +0000 (09:39 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 20 May 2023 07:39:57 +0000 (09:39 +0200)
- introduced fba.fetch_nodeinfo()

fba.py
fetch_blocks.py

diff --git a/fba.py b/fba.py
index 18f2b707969a4a92e24fec1440cb0f37aa97bb6d..c8e2ed09ca5e9b1303afe60fdf94179048f35b27 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -55,40 +55,53 @@ def post_json_api(domain: str, path: str, data: str) -> list:
     # NOISY-DEBUG: print("DEBUG: Returning doc():", len(doc))
     return doc
 
-def determine_software(domain: str) -> str:
-    # NOISY-DEBUG: print("DEBUG: Determining software for domain:", domain)
-    software = None
+def fetch_nodeinfo(domain: str) -> list:
+    print("DEBUG: Fetching nodeinfo from domain:", domain)
+    json = None
     try:
+        print("DEBUG: Fetching 2.1.json from domain:", domain)
         res = reqto.get(f"https://{domain}/nodeinfo/2.1.json", headers=headers, timeout=5)
 
-        # NOISY-DEBUG: print("DEBUG: domain,res.ok,res.status_code:", domain, res.ok, res.status_code)
-        if res.status_code == 404:
+        if res.status_code == 404 or "text/html" in res.headers["content-type"]:
+            print("DEBUG: Fetching 2.0 from domain:", domain)
             res = reqto.get(f"https://{domain}/nodeinfo/2.0", headers=headers, timeout=5)
 
-        if res.status_code == 404:
+        if res.status_code == 404 or "text/html" in res.headers["content-type"]:
+            print("DEBUG: Fetching 2.0.json from domain:", domain)
             res = reqto.get(f"https://{domain}/nodeinfo/2.0.json", headers=headers, timeout=5)
 
         if res.ok and "text/html" in res.headers["content-type"]:
+            print("DEBUG: Fetching 2.1 from domain:", domain)
             res = reqto.get(f"https://{domain}/nodeinfo/2.1", headers=headers, timeout=5)
 
-        if res.ok:
-            json = res.json()
-            # NOISY-DEBUG: print("DEBUG: json():", len(json))
-
-            if json["software"]["name"] in ["akkoma", "rebased"]:
-                software = "pleroma"
-            elif json["software"]["name"] in ["hometown", "ecko"]:
-                software = "mastodon"
-            elif json["software"]["name"] in ["calckey", "groundpolis", "foundkey", "cherrypick"]:
-                software = "misskey"
-            else:
-                software = json["software"]["name"]
-        elif res.status_code == 404:
+        if res.status_code == 404 or "text/html" in res.headers["content-type"]:
+            print("DEBUG: Fetching /api/v1/instance from domain:", domain)
             res = reqto.get(f"https://{domain}/api/v1/instance", headers=headers, timeout=5)
+
+        print("DEBUG: domain,res.ok,res.status_code:", domain, res.ok, res.status_code)
         if res.ok:
-            software = "mastodon"
+            json = res.json()
+
     except:
-        print("WARNING: Failed fetching instance meta data:", domain, software)
+        print("WARNING: Failed fetching nodeinfo from domain:", domain)
+
+    print("DEBUG: Returning json():", len(json))
+    return json
+
+def determine_software(domain: str) -> str:
+    # NOISY-DEBUG: print("DEBUG: Determining software for domain:", domain)
+    software = None
+    json = fetch_nodeinfo(domain)
+    # NOISY-DEBUG: print("DEBUG: json():", len(json))
+
+    if json["software"]["name"] in ["akkoma", "rebased"]:
+        software = "pleroma"
+    elif json["software"]["name"] in ["hometown", "ecko"]:
+        software = "mastodon"
+    elif json["software"]["name"] in ["calckey", "groundpolis", "foundkey", "cherrypick"]:
+        software = "misskey"
+    else:
+        software = json["software"]["name"]
 
     # NOISY-DEBUG: print("DEBUG: Returning domain,software:", domain, software)
     return software
index 170e52ad7ab703ad55b183af6be33409b2860f28..2cc618025603a45d1582e91583ed697be6f520b7 100644 (file)
@@ -23,8 +23,12 @@ for blocker, software in fba.c.fetchall():
         print("INFO: blocker:", blocker)
         try:
             # Blocks
-            federation = reqto.get(f"https://{blocker}/nodeinfo/2.1.json", headers=fba.headers, timeout=5
-            ).json()["metadata"]["federation"]
+            json = fba.fetch_nodeinfo(blocker)
+            if json is None:
+                print("WARNING: Could not fetch nodeinfo from blocker:", blocker)
+                continue
+
+            federation = json["metadata"]["federation"]
 
             if "enabled" in federation:
                 # NOISY-DEBUG: print("DEBUG: Instance has no block list to analyze:", blocker)