1 from requests import get
2 from hashlib import sha256
10 "user-agent": "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
14 def get_hash(domain: str) -> str:
15 return sha256(domain.encode("utf-8")).hexdigest()
18 def get_peers(domain: str) -> str:
20 res = get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=5)
25 peerlist = get_peers(domain)
27 def get_type(instdomain: str) -> str:
29 res = get(f"https://{instdomain}/nodeinfo/2.1.json", headers=headers, timeout=5)
30 if res.status_code == 404:
31 res = get(f"https://{instdomain}/nodeinfo/2.0.json", headers=headers, timeout=5)
32 if res.ok and "text/html" in res.headers["content-type"]:
33 res = get(f"https://{instdomain}/nodeinfo/2.1", headers=headers, timeout=5)
35 if res.json()["software"]["name"] == "akkoma":
38 return res.json()["software"]["name"]
39 elif res.status_code == 404:
40 res = get(f"https://{instdomain}/api/v1/instance", headers=headers, timeout=5)
47 conn = sqlite3.connect("blocks.db")
51 "select domain from instances where 1"
54 for instance in peerlist:
55 instance = instance.lower()
59 "select domain from instances where domain = ?", (instance,)
61 if c.fetchone() == None:
63 "insert into instances select ?, ?, ?",
64 (instance, get_hash(instance), get_type(instance)),
67 except Exception as e:
68 print("error:", e, instance)