From 140666f5b7d0d8ce4bab111d4d9d00cee7ee8ecf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 28 May 2023 13:16:07 +0200 Subject: [PATCH] Continued: - more consistency in table column names and also corresponding variables --- api.py | 22 +++++++++++----------- blocks_empty.db | Bin 28672 -> 28672 bytes fba.py | 8 ++++---- index.html | 2 +- rss.xml | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) 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 bd2bd6ac7a71ea1ec1e2a80336d912ff268be7f6..b83a45698ec8169a185a20908352c3a3b88b1c85 100644 GIT binary patch delta 86 zcmZp8z}WDBae}nqCk6%vb|7X0Vn!g=nW$sT|A|4*dm=AiGXpF4Y6iZ!8}mf@Sb%a; l6CK648daIu#U&*fn^Y(F@>Q}Fr>5pj=H^%2?8?780RS@P6XO5? delta 87 zcmZp8z}WDBae}nqM+OE4b|7X0Vn!g=o~UEY|B*q@dm=Bt4g)LqY6iaMjd`McT#ahX m?BbG=j7{p3m-AJ!CZ?pMrc74hS7ZTdlAP!$y4jU~cLD%R3=`}C 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 %} -- 2.39.5