commit 45d6b10f4015043193a6341f7d2a322203a03034 Author: Ingrid Amim Date: Mon Apr 27 18:27:08 2026 -0500 feat: implementacao inicial da arquitetura de rankings distribuidos diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/app.py new file mode 100644 index 0000000..c51ac7d --- /dev/null +++ b/app.py @@ -0,0 +1,92 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +import requests + +app = FastAPI() + +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_methods=["*"], + allow_headers=["*"], +) + +# Simulando Dados Locais para Consoles +LOCAL_NODES = { + "playstation": [ + {"rank": 1, "name": "Spider-Man 2", "image": "https://image.api.playstation.com/vulcan/ap/rnd/202306/1219/1c7b75d8ed9271516546560d219ad0b22ee0a263b4537bd8.png", "score": "90"}, + {"rank": 2, "name": "God of War Ragnarök", "image": "https://image.api.playstation.com/vulcan/ap/rnd/202207/1210/4xJ8XB3bi888QTLZYdl7Oi0s.png", "score": "94"} + ], + "xbox": [ + {"rank": 1, "name": "Halo Infinite", "image": "https://store-images.s-microsoft.com/image/apps.6040.13727851868390641.c9cc5f66-aff8-406c-af6b-440838730be0.2b6bcbc4-0d19-482f-870d-fcae0cebe2c7", "score": "87"}, + {"rank": 2, "name": "Forza Horizon 5", "image": "https://store-images.s-microsoft.com/image/apps.4606.13886538057288673.eb91334c-2830-46eb-8e54-5264b7d142d7.604ff58f-b98a-40a2-ad3b-638e4a904000", "score": "92"} + ] +} + +@app.get("/ranking/{platform}") +def get_ranking(platform: str): + p = platform.lower() + if p in LOCAL_NODES: return LOCAL_NODES[p] + + # Busca dados ao vivo para PC + store_id = "1" if p == "steam" else "25" + try: + r = requests.get(f"https://www.cheapshark.com/api/1.0/deals?storeID={store_id}&sortBy=Metacritic&pageSize=8").json() + return [{"rank": i+1, "name": g['title'], "image": g['thumb'], "score": g['metacriticScore']} for i, g in enumerate(r) if g['metacriticScore'] != "0"] + except: + return [] + +@app.get("/compare") +def get_compare(): + comparison = [] + + # 1. Pega o Líder PlayStation + if "playstation" in LOCAL_NODES: + comparison.append({ + "platform": "PlayStation", + "name": LOCAL_NODES["playstation"][0]["name"], + "image": LOCAL_NODES["playstation"][0]["image"], + "score": LOCAL_NODES["playstation"][0]["score"] + }) + + # 2. Pega o Líder Xbox + if "xbox" in LOCAL_NODES: + comparison.append({ + "platform": "Xbox Network", + "name": LOCAL_NODES["xbox"][0]["name"], + "image": LOCAL_NODES["xbox"][0]["image"], + "score": LOCAL_NODES["xbox"][0]["score"] + }) + + # 3. Pega o Líder Steam + try: + r_steam = requests.get("https://www.cheapshark.com/api/1.0/deals?storeID=1&sortBy=Metacritic&pageSize=1").json() + if r_steam: + comparison.append({ + "platform": "Steam", + "name": r_steam[0]['title'], + "image": r_steam[0]['thumb'], + "score": r_steam[0]['metacriticScore'] + }) + except: + pass + + # 4. Pega o Líder Epic Games + try: + r_epic = requests.get("https://www.cheapshark.com/api/1.0/deals?storeID=25&sortBy=Metacritic&pageSize=1").json() + if r_epic: + comparison.append({ + "platform": "Epic Games", + "name": r_epic[0]['title'], + "image": r_epic[0]['thumb'], + "score": r_epic[0]['metacriticScore'] + }) + except: + pass + + return comparison + +# Esse é o "motor" que provavelmente tinha sido apagado! +if __name__ == "__main__": + import uvicorn + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..576c553 --- /dev/null +++ b/index.html @@ -0,0 +1,118 @@ + + + + + Ranking por Plataforma + + + + +

Ranking por Plataforma

+ +
+ + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..217daa8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +fastapi +uvicorn +requests +pandas \ No newline at end of file