From 714b2a9521754f5bb508447871b9f9e46b036d05 Mon Sep 17 00:00:00 2001 From: pl608 <78400949+pl608@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:32:20 -0700 Subject: [PATCH] Update api.py Changed method to get playey count from minetest serverlist api (which has a update delay af up to 5 minutes) to ctf api (which I believe has an update time of 30 seconds) --- backend/api.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/backend/api.py b/backend/api.py index 7c901e5..9984153 100644 --- a/backend/api.py +++ b/backend/api.py @@ -17,21 +17,15 @@ class Cache: def _stats() -> Union[Dict[str, Union[str, int]], None]: req_mode_map = requests.get(CTF_API) - req_players = requests.get(SERVER_LIST_API) - if req_mode_map.ok and req_players.ok: + if req_mode_map.ok: j1 = req_mode_map.json() - j2 = [ - x - for x in req_players.json()["list"] - if x["address"] == "ctf.rubenwardy.com" - ][0] - + return { "map_technical": j1["current_map"]["technical_name"], "map": j1["current_map"]["name"], "mode": j1["current_mode"]["name"], - "players": j2["clients"], + "players": j1["player_info"]['count'], "start_time": j1["current_map"]["start_time"] } else: @@ -47,5 +41,5 @@ def stats() -> Union[Dict[str, Union[str, int]], None]: time.sleep(.2) cache = Cache(expire=int(time.time() + CACHE_TIMEOUT), result=result) return result - + return cache.result