]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 07:51:48 +0000 (09:51 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 08:21:58 +0000 (10:21 +0200)
- added top-referencing instances scoreboard

api.py
index.html

diff --git a/api.py b/api.py
index 410e67ea406d2ea83ae1750965ecd19a0484fa73..05debfabba159c379fb8e98cebdc4f4da85ecb16 100644 (file)
--- a/api.py
+++ b/api.py
@@ -25,8 +25,8 @@ def info():
     }
 
 @app.get(fba.config["base_url"] + "/top")
-def top(blocked: int = None, blockers: int = None):
-    if blocked == None and blockers == None:
+def top(blocked: int = None, blockers: int = None, reference: int = None):
+    if blocked == None and blockers == None and reference == None:
         raise HTTPException(status_code=400, detail="No filter specified")
     elif blocked != None:
         if blocked > 500:
@@ -36,6 +36,11 @@ def top(blocked: int = None, blockers: int = None):
         if blockers > 500:
             raise HTTPException(status_code=400, detail="Too many results")
         fba.c.execute("SELECT blocker, COUNT(blocker) FROM blocks WHERE block_level = 'reject' group by blocker ORDER BY COUNT(blocker) DESC LIMIT ?", [blockers])
+    elif reference != None:
+        if reference > 500:
+            raise HTTPException(status_code=400, detail="Too many results")
+        fba.c.execute("SELECT origin, COUNT(domain) FROM instances ORDER BY COUNT(domain) DESC LIMIT ?", [reference])
+
     scores = fba.c.fetchall()
 
     scoreboard = []
@@ -81,13 +86,17 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None):
     return result
 
 @app.get(fba.config["base_url"] + "/scoreboard")
-def index(request: Request, blockers: int = None, blocked: int = None):
-    if blockers == None and blocked == None:
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None):
+    scores = None
+
+    if blockers == None and blocked == None and reference == None:
         raise HTTPException(status_code=400, detail="No filter specified")
     elif blockers != None:
         scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
     elif blocked != None:
         scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
+    elif reference != None:
+        scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
 
     if scores != None:
         if not scores.ok:
@@ -101,6 +110,7 @@ def index(request: Request, blockers: int = None, blocked: int = None):
         "scoreboard": True,
         "blockers": blockers,
         "blocked": blocked,
+        "reference": reference,
         "scores": scores
     })
 
index efdc6e9fafce3dcbad633254505696ea7aac4d74..2b5ca553b24518d24a398229207a88107570df8f 100644 (file)
             <h1>Top {{blockers}} defederating instances</h1>
         {% elif blocked %}
             <h1>Top {{blocked}} defederated instances</h1>
+        {% elif reference %}
+            <h1>Top {{reference}} referencing instances</h1>
         {% endif %}
         <div class="scoreboard">
             <table>
                 <th>№</th>
                 <th>Instance</th>
-                <th>Defederations</th>
+                <th>{% if reference %}References{% else %}Blocks{% endif %}</th>
                 {% for entry in scores %}
                     <tr>
                         <td>{{loop.index}}</td>
             <input type="submit" value="Submit" />
         </form>
         <p>
-            <a href="./scoreboard?blockers=50">top 50 defederating</a> / <a href="./scoreboard?blocked=50">defederated instances</a>
+            <a href="./scoreboard?blockers=50">top 50 defederating</a> /
+            <a href="./scoreboard?blocked=50">defederated instances</a> /
+            <a href="./scoreboard?reference=50">referencing instances</a>
         </p>
         <div class="info">
             known instances: {{info.known_instances}}<br/>