From 83e614dc976f6f35347bad029f8e3e0310482f93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 17 May 2023 06:15:46 +0200 Subject: [PATCH] Continued: - added warning if get_peers() fails - added sys.exit() if this happens for provided instance from command-line --- fetch_instances.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fetch_instances.py b/fetch_instances.py index e983924..20df590 100644 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -21,20 +21,23 @@ headers = { "user-agent": config["useragent"] } - def get_hash(domain: str) -> str: return sha256(domain.encode("utf-8")).hexdigest() - def get_peers(domain: str) -> str: try: res = get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=5) return res.json() except: + print("WARNING: Cannot fetch peers:", domain) return None peerlist = get_peers(domain) +if (peerlist is None): + print("FATAL: CANNOT FETCH PEERS:", domain) + sys.exit(255) + def get_type(instdomain: str) -> str: try: res = get(f"https://{instdomain}/nodeinfo/2.1.json", headers=headers, timeout=5) @@ -65,7 +68,7 @@ conn = sqlite3.connect("blocks.db") c = conn.cursor() c.execute( - "SELECT domain FROM instances WHERE 1" + "SELECT domain FROM instances WHERE 1" ) for instance in peerlist: @@ -82,7 +85,7 @@ for instance in peerlist: print(instance) try: c.execute( - "SELECT domain FROM instances WHERE domain = ?", (instance,) + "SELECT domain FROM instances WHERE domain = ?", (instance,) ) if c.fetchone() == None: c.execute( -- 2.39.5