From 433bcd3f005b23142ebf6a945142c79686fa4ea9 Mon Sep 17 00:00:00 2001 From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Fri, 8 Apr 2022 22:07:05 +0200 Subject: [PATCH] added better way of getting the software type --- fetch_blocks.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fetch_blocks.py b/fetch_blocks.py index c37791a..60d90c1 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -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() -- 2.39.5