]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 28 May 2023 11:16:07 +0000 (13:16 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 28 May 2023 11:16:07 +0000 (13:16 +0200)
- more consistency in table column names and also corresponding variables

api.py
blocks_empty.db
fba.py
index.html
rss.xml

diff --git a/api.py b/api.py
index 790a0809975947a4f49d50be62845eb50e445c21..f53a684d1bbe6e1b7fc9af424739dcc9df292ff2 100644 (file)
--- 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())
index bd2bd6ac7a71ea1ec1e2a80336d912ff268be7f6..b83a45698ec8169a185a20908352c3a3b88b1c85 100644 (file)
Binary files a/blocks_empty.db and b/blocks_empty.db differ
diff --git a/fba.py b/fba.py
index e408952d00b9d029f2d49e973117e6133438c8fa..82bf0290aa9e4147f25657a5987c4bb039eeb9c2 100644 (file)
--- 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!")
index 3f0d7c6865a3c7ee306a467b3f76f196678fd4ae..6bd9f80f8eec300f7dbda851fabcaf399395dcb9 100644 (file)
                                 {% if reason or reverse %}<a class="listlink" href="{{base_url}}/?domain={{domain or block['blocked']}}">↘</a>{% endif %}
                             </td>
                             <td>{{block['reason']}}</td>
-                            <td>{{block['first_added']}}</td>
+                            <td>{{block['first_seen']}}</td>
                             <td>{{block['last_seen']}}</td>
                         </tr>
                     {% endfor %}
diff --git a/rss.xml b/rss.xml
index eecfa318a310ec4877b1b3a9990e6f46d7e20f22..5d63df9db2f1c7ce6318c4895b6ca3257e18f071 100644 (file)
--- a/rss.xml
+++ b/rss.xml
@@ -10,7 +10,7 @@
   <title>{{block['blocker']}} has applied '{{block['block_level']}}' restriction to {{block['blocked']}}</title>
   <description>{{block['reason']}}</description>
   <link>https://fba.ryona.agency/?reverse={{block['blocker']}}</link>
-  <pubDate>{{block['first_added']}}</pubDate>
+  <pubDate>{{block['first_seen']}}</pubDate>
  </item>
  {% endfor %}
 </channel>