From: Roland Häder Date: Sun, 28 May 2023 11:16:07 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=140666f5b7d0d8ce4bab111d4d9d00cee7ee8ecf;p=fba.git Continued: - more consistency in table column names and also corresponding variables --- diff --git a/api.py b/api.py index 790a080..f53a684 100644 --- a/api.py +++ b/api.py @@ -69,21 +69,21 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): if domain != None: wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):]) punycode = domain.encode('idna').decode('utf-8') - fba.cursor.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", + fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_seen ASC", (domain, "*." + domain, wildchar, fba.get_hash(domain), punycode, "*." + punycode)) elif reverse != None: - fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? ORDER BY first_added ASC", [reverse]) + fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE blocker = ? ORDER BY first_seen ASC", [reverse]) else: - fba.cursor.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.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_seen ASC", ["%" + reason + "%"]) blocks = fba.cursor.fetchall() result = {} - for blocker, blocked, block_level, reason, first_added, last_seen in blocks: + for blocker, blocked, block_level, reason, first_seen, last_seen in blocks: entry = { "blocker" : blocker, "blocked" : blocked, "reason" : reason, - "first_added": first_added, + "first_seen": first_seen, "last_seen" : last_seen } if block_level in result: @@ -152,7 +152,7 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str blocks = blocks.json() for block_level in blocks: for block in blocks[block_level]: - block["first_added"] = datetime.utcfromtimestamp(block["first_added"]).strftime('%Y-%m-%d %H:%M') + block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime('%Y-%m-%d %H:%M') block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime('%Y-%m-%d %H:%M') return templates.TemplateResponse("index.html", { @@ -193,16 +193,16 @@ def rss(request: Request, domain: str = None): if domain != None: wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):]) punycode = domain.encode('idna').decode('utf-8') - fba.cursor.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 DESC LIMIT 50", + fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_seen DESC LIMIT 50", (domain, "*." + domain, wildchar, fba.get_hash(domain), punycode, "*." + punycode)) else: - fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks ORDER BY first_added DESC LIMIT 50") + fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks ORDER BY first_seen DESC LIMIT 50") blocks = fba.cursor.fetchall() result = [] - for blocker, blocked, block_level, reason, first_added, last_seen in blocks: - first_added = utils.format_datetime(datetime.fromtimestamp(first_added)) + for blocker, blocked, block_level, reason, first_seen, last_seen in blocks: + first_seen = utils.format_datetime(datetime.fromtimestamp(first_seen)) if reason == None or reason == '': reason = "No reason provided." else: @@ -213,7 +213,7 @@ def rss(request: Request, domain: str = None): "blocked": blocked, "block_level": block_level, "reason": reason, - "first_added": first_added + "first_seen": first_seen }) timestamp = utils.format_datetime(datetime.now()) diff --git a/blocks_empty.db b/blocks_empty.db index bd2bd6a..b83a456 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/fba.py b/fba.py index e408952..82bf029 100644 --- a/fba.py +++ b/fba.py @@ -749,10 +749,10 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str): print("WARNING: Bad blocked:", blocked) raise - print("INFO: New block:", blocker, blocked, reason, block_level, first_added, last_seen) + print("INFO: New block:", blocker, blocked, reason, block_level, first_seen, last_seen) try: cursor.execute( - "INSERT INTO blocks (blocker, blocked, reason, block_level, first_added, last_seen) VALUES(?, ?, ?, ?, ?, ?)", + "INSERT INTO blocks (blocker, blocked, reason, block_level, first_seen, last_seen) VALUES(?, ?, ?, ?, ?, ?)", ( blocker, blocked, @@ -764,7 +764,7 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str): ) except BaseException as e: - print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',first_added='{first_added}',last_seen='{last_seen}',exception:'{e}'") + print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',first_seen='{first_seen}',last_seen='{last_seen}',exception:'{e}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!") @@ -782,7 +782,7 @@ def is_instance_registered(domain: str) -> bool: # Check condition registered = cursor.fetchone() != None except BaseException as e: - print(f"ERROR: failed SQL query: last_seen='{last_seen}'blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',first_added='{first_added}',last_seen='{last_seen}',exception:'{e}'") + print(f"ERROR: failed SQL query: last_seen='{last_seen}'blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',first_seen='{first_seen}',last_seen='{last_seen}',exception:'{e}'") sys.exit(255) # DEBUG: print(f"DEBUG: registered='{registered}' - EXIT!") diff --git a/index.html b/index.html index 3f0d7c6..6bd9f80 100644 --- a/index.html +++ b/index.html @@ -143,7 +143,7 @@ {% if reason or reverse %}↘{% endif %} {{block['reason']}} - {{block['first_added']}} + {{block['first_seen']}} {{block['last_seen']}} {% endfor %} diff --git a/rss.xml b/rss.xml index eecfa31..5d63df9 100644 --- a/rss.xml +++ b/rss.xml @@ -10,7 +10,7 @@ {{block['blocker']}} has applied '{{block['block_level']}}' restriction to {{block['blocked']}} {{block['reason']}} https://fba.ryona.agency/?reverse={{block['blocker']}} - {{block['first_added']}} + {{block['first_seen']}} {% endfor %}