From b8911fd4eef2687646b388f59c4c6f27e06e32fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 20 May 2023 10:26:29 +0200 Subject: [PATCH] WIP: - introduced update_last_access() which will update 'last_access' by instance's domain --- fba.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fba.py b/fba.py index 8c90f77..c78dd64 100644 --- a/fba.py +++ b/fba.py @@ -31,6 +31,19 @@ def get_hash(domain: str) -> str: # NOISY-DEBUG: print("DEBUG: Calculating hash for domain:", domain) return sha256(domain.encode("utf-8")).hexdigest() +def update_last_access(domain: str): + # NOISY-DEBUG: print("DEBUG: Updating last_access for domain:", domain) + + try: + c.execute("UPDATE instances SET last_access = ? WHERE domain = ?", [ + time.time(), + domain + ]) + + except: + print("ERROR: failed SQL query:", domain) + sys.exit(255) + def get_peers(domain: str) -> str: # NOISY-DEBUG: print("DEBUG: Getting peers for domain:", domain) peers = None @@ -41,6 +54,9 @@ def get_peers(domain: str) -> str: except: print("WARNING: Cannot fetch peers:", domain) + if peers is not None: + update_last_access(domain) + # NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers @@ -51,6 +67,8 @@ def post_json_api(domain: str, path: str, data: str) -> list: if not res.ok: print("WARNING: Cannot query JSON API:", domain, path, data, res.status_code) raise + else: + update_last_access(domain) doc = res.json() # NOISY-DEBUG: print("DEBUG: Returning doc():", len(doc)) @@ -88,6 +106,8 @@ def fetch_nodeinfo(domain: str) -> list: if json is None: print("WARNING: Failed fetching nodeinfo from domain:", domain) + else: + update_last_access(domain) # NOISY-DEBUG: print("DEBUG: Returning json():", len(json)) return json -- 2.39.5