Spaces:
Sleeping
Sleeping
league id input change
Browse files
app.py
CHANGED
@@ -4,14 +4,23 @@ import requests
|
|
4 |
# Sleeper API ์๋ํฌ์ธํธ
|
5 |
BASE_URL = "https://api.sleeper.app/v1"
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# ์ ์ ์ด๋ฆ์ ๊ฐ์ ธ์ค๊ธฐ ์ํ ์ ํธ๋ฆฌํฐ ํจ์
|
8 |
def fetch_players():
|
9 |
url = f"{BASE_URL}/players/nba"
|
10 |
response = requests.get(url)
|
11 |
if response.status_code == 200:
|
12 |
players_data = response.json()
|
13 |
-
|
14 |
-
return {player_id: data["full_name"] for player_id, data in players_data.items() if "full_name" in data.keys()}
|
15 |
else:
|
16 |
return {}
|
17 |
|
@@ -43,19 +52,34 @@ def get_weekly_matchup(league_id, week):
|
|
43 |
return results
|
44 |
|
45 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
46 |
-
def display_weekly_matchup(
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
50 |
iface = gr.Interface(
|
51 |
fn=display_weekly_matchup,
|
52 |
inputs=[
|
53 |
-
gr.
|
54 |
-
gr.Number(label="
|
55 |
],
|
56 |
outputs=gr.JSON(),
|
57 |
-
title="ํํ์ง NBA
|
58 |
-
description="Sleeper API๋ฅผ ์ฌ์ฉํ์ฌ
|
59 |
)
|
60 |
|
61 |
if __name__ == "__main__":
|
|
|
4 |
# Sleeper API ์๋ํฌ์ธํธ
|
5 |
BASE_URL = "https://api.sleeper.app/v1"
|
6 |
|
7 |
+
# ๋ฆฌ๊ทธ ์ด๋ฆ์ ๊ฐ์ ธ์ค๊ธฐ ์ํ ํจ์
|
8 |
+
def fetch_league_name(league_id):
|
9 |
+
url = f"{BASE_URL}/league/{league_id}"
|
10 |
+
response = requests.get(url)
|
11 |
+
if response.status_code == 200:
|
12 |
+
league_data = response.json()
|
13 |
+
return league_data.get("name", f"๋ฆฌ๊ทธ ์ด๋ฆ ์์ ({league_id})")
|
14 |
+
else:
|
15 |
+
return f"๋ฆฌ๊ทธ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ ์คํจ ({league_id})"
|
16 |
+
|
17 |
# ์ ์ ์ด๋ฆ์ ๊ฐ์ ธ์ค๊ธฐ ์ํ ์ ํธ๋ฆฌํฐ ํจ์
|
18 |
def fetch_players():
|
19 |
url = f"{BASE_URL}/players/nba"
|
20 |
response = requests.get(url)
|
21 |
if response.status_code == 200:
|
22 |
players_data = response.json()
|
23 |
+
return {player_id: data["full_name"] for player_id, data in players_data.items()}
|
|
|
24 |
else:
|
25 |
return {}
|
26 |
|
|
|
52 |
return results
|
53 |
|
54 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
55 |
+
def display_weekly_matchup(league_name, week):
|
56 |
+
league_ids = {
|
57 |
+
fetch_league_name("1149290874371846144"): "1149290874371846144",
|
58 |
+
fetch_league_name("1083634148067074048"): "1083634148067074048",
|
59 |
+
}
|
60 |
+
league_id = league_ids.get(league_name)
|
61 |
+
if not league_id:
|
62 |
+
return {"error": "์ ํจํ์ง ์์ ๋ฆฌ๊ทธ ์ด๋ฆ์
๋๋ค."}
|
63 |
+
|
64 |
+
return get_weekly_matchup(league_id, int(week))
|
65 |
+
|
66 |
+
# ๋ฆฌ๊ทธ ์ด๋ฆ์ ๋๋กญ๋ค์ด์ ๋์ ์ผ๋ก ์ถ๊ฐ
|
67 |
+
def get_league_choices():
|
68 |
+
return [
|
69 |
+
fetch_league_name("1149290874371846144"),
|
70 |
+
fetch_league_name("1083634148067074048"),
|
71 |
+
]
|
72 |
|
73 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
74 |
iface = gr.Interface(
|
75 |
fn=display_weekly_matchup,
|
76 |
inputs=[
|
77 |
+
gr.Dropdown(choices=get_league_choices(), label="๋ฆฌ๊ทธ ์ ํ"),
|
78 |
+
gr.Number(label="์ฃผ์ฐจ ์
๋ ฅ (์ซ์)"),
|
79 |
],
|
80 |
outputs=gr.JSON(),
|
81 |
+
title="ํํ์ง NBA ๋ฆฌ๊ทธ ๋งค์น์
์ ๋ณด",
|
82 |
+
description="Sleeper API๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๊ทธ ์ด๋ฆ๊ณผ ์ฃผ์ฐจ๋ณ ๋งค์น์
์ ๋ณด๋ฅผ ํ์ธํฉ๋๋ค."
|
83 |
)
|
84 |
|
85 |
if __name__ == "__main__":
|