]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 19 May 2023 16:45:19 +0000 (18:45 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 19 May 2023 16:45:19 +0000 (18:45 +0200)
- more formatting

api.py
fba.py
fetch_blocks.py

diff --git a/api.py b/api.py
index 30e06bdcdad875e96b92e72cd6c2d5150ab790b2..f9605e3811d554e848b7c31b5f7771afbcb1432d 100644 (file)
--- a/api.py
+++ b/api.py
@@ -1,10 +1,11 @@
-import uvicorn
 from fastapi import FastAPI, Request, HTTPException, responses, Query
-import sqlite3
 from fastapi.templating import Jinja2Templates
 from requests import get
 from datetime import datetime
 from email import utils
+
+import uvicorn
+import sqlite3
 import re
 import fba
 
@@ -55,17 +56,23 @@ 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.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",
+        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 = {}
     for blocker, blocked, block_level, reason, first_added, last_seen in blocks:
-        entry = {"blocker": blocker, "blocked": blocked, "reason": reason, "first_added": first_added, "last_seen": last_seen}
+        entry = {
+            "blocker": blocker,
+            "blocked": blocked,
+            "reason": reason,
+            "first_added": first_added,
+            "last_seen": last_seen
+        }
         if block_level in result:
             result[block_level].append(entry)
         else:
@@ -159,19 +166,24 @@ def rss(request: Request, domain: str = None):
         else:
             reason = "Provided reason: '" + reason + "'"
 
-        result.append(
-            {
+        result.append({
             "blocker": blocker,
             "blocked": blocked,
             "block_level": block_level,
             "reason": reason,
             "first_added": first_added
-            }
-        )
+        })
 
     timestamp = utils.format_datetime(datetime.now())
 
-    return templates.TemplateResponse("rss.xml", {"request": request, "timestamp": timestamp, "domain": domain, "blocks": result}, headers={"Content-Type": "application/rss+xml"})
+    return templates.TemplateResponse("rss.xml", {
+        "request": request,
+        "timestamp": timestamp,
+        "domain": domain,
+        "blocks": result
+    }, headers={
+        "Content-Type": "application/rss+xml"
+    })
 
 if __name__ == "__main__":
     uvicorn.run("api:app", host="127.0.0.1", port=fba.config["port"], log_level=fba.config["log_level"])
diff --git a/fba.py b/fba.py
index 188fb70e0b76aaf8d993df56019c3a3cb0d3f3d5..c18c623802d088eb45cf25ae76a2faada6c6465b 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -1,5 +1,6 @@
 from bs4 import BeautifulSoup
 from hashlib import sha256
+
 import reqto
 import re
 import sqlite3
@@ -32,7 +33,7 @@ def get_peers(domain: str) -> str:
         res = reqto.get(f"https://{domain}/api/v1/instance/peers", headers=headers, timeout=5)
         return res.json()
     except:
-        print("WARNING: Cannot fetch peers:", domain)
+        print("WARNING: Cannot fetch peers:", domain, res.status_code)
         return None
 
 def get_type(instdomain: str) -> str:
index 343b67baf3f531cbf641f69e669cff1fc23c6fc8..cf9d97c77c70ab7ee8c6b4ea8814e3a000199baa 100644 (file)
@@ -6,7 +6,7 @@ import itertools
 import re
 
 fba.c.execute(
-    "SELECT domain, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial')"
+    "SELECT domain, software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial') ORDER BY rowid DESC"
 )
 
 for blocker, software in fba.c.fetchall():