From 5be51bf199ba389a87152eef91de757cb5af271a Mon Sep 17 00:00:00 2001 From: "Aeru Y." Date: Sat, 17 Oct 2026 02:27:56 +0200 Subject: [PATCH] Add main.py --- main.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..555b8cd --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +import threading +import time +import fastapi +import requests + +app = fastapi.FastAPI() +lanyard_link = "https://api.lanyard.rest/v1/users/1558056824387805300" +CACHE_TTL = 1.0 +_cache = {"data": None, "time": 0.0} +_lock = threading.Lock() + + + +def get_lanyard(): + if _cache["data"] is not None and time.monotonic() - _cache["time"] < CACHE_TTL: + return _cache["data"] + with _lock: + if _cache["data"] is not None and time.monotonic() - _cache["time"] < CACHE_TTL: + return _cache["data"] + try: + response = requests.get(lanyard_link, timeout=5) + response.raise_for_status() + _cache["data"] = response.json() + _cache["time"] = time.monotonic() + except requests.RequestException: + if _cache["data"] is None: + raise fastapi.HTTPException(status_code=502, detail="Lanyard indisponible") + return _cache["data"] + + +@app.get("/") +def read_root(): + return {"message": "Welcome to IKAVOID API (5005)"} +@app.get("/discord") +def read_lanyard(): + return get_lanyard() + + +if __name__ == "__main__": + import uvicorn + uvicorn.run(app, host="0.0.0.0", port=5005) \ No newline at end of file