]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 23 Jul 2023 17:14:31 +0000 (19:14 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 23 Jul 2023 17:14:31 +0000 (19:14 +0200)
- simplified some lines ({node})

daemon.py

index eca99441537f26327bf2e612da43a5abf52ca2a9..aaa8d0ca94ce70ae2c0efb4ebb92db8d9c3af0d6 100755 (executable)
--- a/daemon.py
+++ b/daemon.py
@@ -98,10 +98,10 @@ def api_scoreboard(mode: str, amount: int):
 
     scores = list()
 
-    for domain, score in database.cursor.fetchall():
+    for row in database.cursor.fetchall():
         scores.append({
-            "domain": domain,
-            "score" : round(score)
+            "domain": row[0],
+            "score" : round(row[1]),
         })
 
     return JSONResponse(status_code=200, content=scores)
@@ -333,32 +333,12 @@ def api_peers(request: Request):
 
 @router.get(config.get("base_url") + "/scoreboard")
 def scoreboard(request: Request, mode: str, amount: int):
-    response = None
-
-    if mode == "blocker" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=blocker&amount={amount}")
-    elif mode == "blocked" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=blocked&amount={amount}")
-    elif mode == "reference" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=reference&amount={amount}")
-    elif mode == "software" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=software&amount={amount}")
-    elif mode == "command" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=command&amount={amount}")
-    elif mode == "error_code" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=error_code&amount={amount}")
-    elif mode == "detection_mode" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=detection_mode&amount={amount}")
-    elif mode == "avg_peers" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=avg_peers&amount={amount}")
-    elif mode == "obfuscator" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=obfuscator&amount={amount}")
-    elif mode == "obfuscation" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=obfuscation&amount={amount}")
-    elif mode == "block_level" and amount > 0:
-        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode=block_level&amount={amount}")
-    else:
-        raise HTTPException(status_code=400, detail="No filter specified")
+    if mode == "":
+        raise HTTPException(status_code=400, detail="No mode specified")
+    elif amount <= 0:
+        raise HTTPException(status_code=500, detail="Invalid amount specified")
+
+    response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/scoreboard.json?mode={mode}&amount={amount}")
 
     if response is None:
         raise HTTPException(status_code=500, detail="Could not determine scores")