]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 09:38:41 +0000 (11:38 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 21 May 2023 09:39:02 +0000 (11:39 +0200)
- added top X for used software

api.py
index.html

diff --git a/api.py b/api.py
index d6ce394a2a794e5165481952d7d1d819eb07c472..f0e11ef8f0b8ec0249c1f50b1573835e49560c0a 100644 (file)
--- a/api.py
+++ b/api.py
@@ -25,21 +25,25 @@ def info():
     }
 
 @app.get(fba.config["base_url"] + "/top")
-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:
+def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None):
+    if blocked != None:
         if blocked > 500:
             raise HTTPException(status_code=400, detail="Too many results")
-        fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' group by blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked])
+        fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' GROUP BY blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked])
     elif blockers != 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])
+        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])
+        fba.c.execute("SELECT origin, COUNT(domain) FROM instances GROUP BY origin ORDER BY COUNT(domain) DESC LIMIT ?", [reference])
+    elif software != None:
+        if software > 500:
+            raise HTTPException(status_code=400, detail="Too many results")
+        fba.c.execute("SELECT software, COUNT(domain) FROM instances GROUP BY software ORDER BY COUNT(domain) DESC LIMIT ?", [software])
+    else:
+        raise HTTPException(status_code=400, detail="No filter specified")
 
     scores = fba.c.fetchall()
 
@@ -72,11 +76,11 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None):
     result = {}
     for blocker, blocked, block_level, reason, first_added, last_seen in blocks:
         entry = {
-            "blocker": blocker,
-            "blocked": blocked,
-            "reason": reason,
+            "blocker"    : blocker,
+            "blocked"    : blocked,
+            "reason"     : reason,
             "first_added": first_added,
-            "last_seen": last_seen
+            "last_seen"  : last_seen
         }
         if block_level in result:
             result[block_level].append(entry)
@@ -86,19 +90,21 @@ 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, reference: int = None, ):
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: 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:
+    if blockers != None and blockers > 0:
         scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
-    elif blocked != None:
+    elif blocked != None and blocked > 0:
         scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
-    elif reference != None:
+    elif reference != None and reference > 0:
         scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
+    elif software != None and software > 0:
+        scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?software={software}")
+    else:
+        raise HTTPException(status_code=400, detail="No filter specified")
 
-    if scores = None:
+    if scores == None:
         raise HTTPException(status_code=500, detail="Could not determine scores")
     elif not scores.ok:
         raise HTTPException(status_code=scores.status_code, detail=scores.text)
@@ -110,6 +116,7 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
         "blockers"  : blockers,
         "blocked"   : blocked,
         "reference" : reference,
+        "software"  : software,
         "scores"    : scores.json()
     })
 
index 2b5ca553b24518d24a398229207a88107570df8f..bcc8bb153c4900027fcc4d30204dc59d71d8e0a6 100644 (file)
             <h1>Top {{blocked}} defederated instances</h1>
         {% elif reference %}
             <h1>Top {{reference}} referencing instances</h1>
+        {% elif software %}
+            <h1>Top {{software}} used software</h1>
         {% endif %}
         <div class="scoreboard">
             <table>
                 <th>№</th>
-                <th>Instance</th>
-                <th>{% if reference %}References{% else %}Blocks{% endif %}</th>
+                <th>{% if software %}Software{% else %}Instance{% endif %}</th>
+                <th>{% if reference %}References{% elif software %}Total{% else %}Blocks{% endif %}</th>
                 {% for entry in scores %}
                     <tr>
                         <td>{{loop.index}}</td>
                         <td>
-                            <img src="https://proxy.duckduckgo.com/ip3/{{entry['domain']}}.ico" width="16" />
-                            <b><a href="../?{% if blockers %}reverse{% elif blocked %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a></b>&nbsp;
-                            <a class="listlink" href="https://{{entry['domain']}}" rel="external" target="_blank">↗</a>
+                            {% if software %}
+                            {{entry['domain']}}
+                            {% else %}
+                                <b><a href="../?{% if blockers %}reverse{% elif blocked %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a></b>&nbsp;
+                                <a class="listlink" href="https://{{entry['domain']}}" rel="external" target="_blank">↗</a>
+                            {% endif %}
                         </td>
                         <td>{{entry['highscore']}}</td>
                     </tr>
         <p>
             <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>
+            <a href="./scoreboard?reference=50">referencing instances</a> /
+            <a href="./scoreboard?software=50">used software</a>
         </p>
         <div class="info">
             known instances: {{info.known_instances}}<br/>