]> git.mxchange.org Git - fba.git/blobdiff - api.py
Continued:
[fba.git] / api.py
diff --git a/api.py b/api.py
index 33d09f514e1b948865f8396eda8abc9e2d9ef299..da4a2ee65396846933cc0a80a5449e6c8027c52c 100644 (file)
--- a/api.py
+++ b/api.py
@@ -236,10 +236,11 @@ def top(request: Request, domain: str = None, reason: str = None, reverse: str =
             raise HTTPException(status_code=response.status_code, detail=response.text)
 
         blocklist = response.json()
+
         for block_level in blocklist:
             for block in blocklist[block_level]:
                 block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime(config.get("timestamp_format"))
-                block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime(config.get("timestamp_format"))
+                block["last_seen"]  = datetime.utcfromtimestamp(block["last_seen"]).strftime(config.get("timestamp_format"))
 
     return templates.TemplateResponse("views/top.html", {
         "request": request,
@@ -256,18 +257,25 @@ def rss(request: Request, domain: str = None):
         domain = tidyup.domain(domain)
 
         wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
-        punycode = domain.encode('idna').decode('utf-8')
-        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))
+        punycode = domain.encode("idna").decode("utf-8")
+
+        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 ?", [
+            domain,
+            "*." + domain, wildchar,
+            fba.get_hash(domain),
+            punycode,
+            "*." + punycode,
+            config.get("rss_limit")
+        ])
     else:
-        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks ORDER BY first_seen DESC LIMIT 50")
+        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks ORDER BY first_seen DESC LIMIT ?", [config.get("rss_limit")])
 
     result = fba.cursor.fetchall()
 
     blocklist = []
     for blocker, blocked, block_level, reason, first_seen, last_seen in result:
         first_seen = utils.format_datetime(datetime.fromtimestamp(first_seen))
-        if reason is None or reason == '':
+        if reason is None or reason == "":
             reason = "No reason provided."
         else:
             reason = "Provided reason: '" + reason + "'"