From: Roland Häder Date: Sun, 23 Jul 2023 17:14:31 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2c749e50c9ba92c8184e9ebf50c98c2b422c2a85;p=fba.git Continued: - simplified some lines ({node}) --- diff --git a/daemon.py b/daemon.py index eca9944..aaa8d0c 100755 --- 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")