From: Roland Häder Date: Sat, 20 May 2023 12:36:59 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d164a5233f489941494c0401a288b0d379fdbe11;p=fba.git Continued: - looks cooler this way --- diff --git a/api.py b/api.py index bd1e376..410e67e 100644 --- a/api.py +++ b/api.py @@ -31,11 +31,11 @@ def top(blocked: int = None, blockers: int = None): elif blocked != None: if blocked > 500: raise HTTPException(status_code=400, detail="Too many results") - fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' group by blocked ORDER BY COUNT(blocked) DESC LIMIT ?", (blocked,)) + fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' group by blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked]) elif blockers != None: if blockers > 500: raise HTTPException(status_code=400, detail="Too many results") - fba.c.execute("SELECT blocker, COUNT(blocker) FROM blocks WHERE block_level = 'reject' group by blocker ORDER BY COUNT(blocker) DESC LIMIT ?", (blockers,)) + fba.c.execute("SELECT blocker, COUNT(blocker) FROM blocks WHERE block_level = 'reject' group by blocker ORDER BY COUNT(blocker) DESC LIMIT ?", [blockers]) scores = fba.c.fetchall() scoreboard = [] @@ -59,9 +59,9 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_added ASC", (domain, "*." + domain, wildchar, fba.get_hash(domain), punycode, "*." + punycode)) elif reverse != None: - fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? ORDER BY first_added ASC", (reverse,)) + fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? ORDER BY first_added ASC", [reverse]) else: - fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_added ASC", ("%"+reason+"%",)) + fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_added ASC", ["%" + reason + "%"]) blocks = fba.c.fetchall() result = {} diff --git a/fetch_blocks.py b/fetch_blocks.py index 93b6134..2a13023 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -61,7 +61,7 @@ for blocker, software in fba.c.fetchall(): if blocked.count("*") > 1: # -ACK!-oma also started obscuring domains without hash fba.c.execute( - "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),) + "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")] ) searchres = fba.c.fetchone() # NOISY-DEBUG: print("DEBUG: searchres[]:", type(searchres)) @@ -71,7 +71,7 @@ for blocker, software in fba.c.fetchall(): # NOISY-DEBUG: print("DEBUG: Looking up instance by domain:", blocked) fba.c.execute( - "SELECT domain FROM instances WHERE domain = ?", (blocked,) + "SELECT domain FROM instances WHERE domain = ?", [blocked] ) if fba.c.fetchone() == None: @@ -133,7 +133,7 @@ for blocker, software in fba.c.fetchall(): elif blocked.count("*") > 1: # same domain guess as above, but for reasons field fba.c.execute( - "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),) + "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")] ) searchres = fba.c.fetchone() @@ -224,7 +224,7 @@ for blocker, software in fba.c.fetchall(): elif blocked.count("*") < 1: # No obsfucation for this instance fba.c.execute( - "SELECT hash FROM instances WHERE domain = ? LIMIT 1", (blocked,) + "SELECT hash FROM instances WHERE domain = ? LIMIT 1", [blocked] ) if fba.c.fetchone() == None: @@ -233,7 +233,7 @@ for blocker, software in fba.c.fetchall(): else: # Doing the hash search for instance names as well to tidy up DB fba.c.execute( - "SELECT domain FROM instances WHERE hash = ? LIMIT 1", (blocked_hash,) + "SELECT domain FROM instances WHERE hash = ? LIMIT 1", [blocked_hash] ) searchres = fba.c.fetchone() @@ -298,7 +298,7 @@ for blocker, software in fba.c.fetchall(): if blocked.count("*") > 0: # Some friendica servers also obscure domains without hash fba.c.execute( - "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),) + "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")] ) searchres = fba.c.fetchone() if searchres != None: @@ -307,7 +307,7 @@ for blocker, software in fba.c.fetchall(): if blocked.count("?") > 0: # Some obscure them with question marks, not sure if that's dependent on version or not fba.c.execute( - "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("?", "_"),) + "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("?", "_")] ) searchres = fba.c.fetchone() if searchres != None: @@ -315,7 +315,7 @@ for blocker, software in fba.c.fetchall(): # NOISY-DEBUG: print("DEBUG: AFTER-blocked:", blocked) fba.c.execute( - "SELECT domain FROM instances WHERE domain = ?", (blocked,) + "SELECT domain FROM instances WHERE domain = ?", [blocked] ) if fba.c.fetchone() == None: @@ -370,7 +370,7 @@ for blocker, software in fba.c.fetchall(): if blocked.count("*") > 0: # GTS does not have hashes for obscured domains, so we have to guess it fba.c.execute( - "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),) + "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")] ) searchres = fba.c.fetchone() @@ -378,7 +378,7 @@ for blocker, software in fba.c.fetchall(): blocked = searchres[0] fba.c.execute( - "SELECT domain FROM instances WHERE domain = ?", (blocked,) + "SELECT domain FROM instances WHERE domain = ?", [blocked] ) if fba.c.fetchone() == None: diff --git a/fetch_instances.py b/fetch_instances.py index fb1ba01..cc855e6 100644 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -5,14 +5,14 @@ import time import fba def fetch_instances(domain: str): - print("DEBUG: Fetching instances for domain:", domain) + # NOISY-DEBUG: print("DEBUG: Fetching instances for domain:", domain) peerlist = fba.get_peers(domain) if (peerlist is None): print("ERROR: Cannot fetch peers:", domain) fba.c.execute( - "SELECT domain FROM instances WHERE domain = ? LIMIT 1", (domain,) + "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [domain] ) if fba.c.fetchone() == None: @@ -40,7 +40,7 @@ def fetch_instances(domain: str): # NOISY-DEBUG: print("DEBUG: Handling instance:", instance) try: fba.c.execute( - "SELECT domain FROM instances WHERE domain = ? LIMIT 1", (instance,) + "SELECT domain FROM instances WHERE domain = ? LIMIT 1", [instance] ) if fba.c.fetchone() == None: @@ -73,7 +73,7 @@ for instance in fba.c.fetchall(): # NOISY-DEBUG: print("DEBUG: domain is blacklisted:", instance) continue - print("DEBUG: Fetching instances for instance:", instance[0]) + print("INFO: Fetching instances for instance:", instance[0]) fetch_instances(instance[0]) fba.conn.close()