]> git.mxchange.org Git - fba.git/commitdiff
added better way of getting the software type
authorEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 8 Apr 2022 20:07:05 +0000 (22:07 +0200)
committerEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 8 Apr 2022 20:07:05 +0000 (22:07 +0200)
fetch_blocks.py

index c37791a6c15a0264cd6a3da32a9c701721aff4ad..60d90c1bfff8b5acd683a9e6b7e76c815c4b6c58 100644 (file)
@@ -30,17 +30,17 @@ def get_mastodon_blocks(domain: str) -> dict:
 
 def get_type(domain: str) -> str:
     try:
-        res = get("https://"+domain, headers=headers, timeout=5)
-        if "pleroma" in res.text.lower():
-            print("pleroma")
-            return "pleroma"
-        elif "mastodon" in res.text.lower():
-            print("mastodon")
+        res = get(f"https://{domain}/nodeinfo/2.1.json", headers=headers, timeout=5)
+        if res.status_code == 404:
+            res = get(f"https://{domain}/nodeinfo/2.0.json", headers=headers, timeout=5)
+        if res.ok:
+            return res.json()["software"]["name"]
+        elif res.status_code == 404:
+            res = get(f"https://{domain}/api/v1/instance", headers=headers, timeout=5)
+        if res.ok:
             return "mastodon"
-        return ""
-    except Exception as e:
-        print("error:", e, domain)
-        return ""
+    except:
+        return None
 
 conn = sqlite3.connect("blocks.db")
 c = conn.cursor()