Spaces:
Sleeping
Sleeping
Commit
·
ce0caba
1
Parent(s):
0703c90
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
from datetime import datetime, timedelta
|
|
|
5 |
|
6 |
def fetch_games_by_date(date, api_key):
|
7 |
url = f"https://api.sportsdata.io/v3/nba/scores/json/GamesByDate/{date}?key={api_key}"
|
@@ -20,20 +21,24 @@ def last_30_days_data(api_key):
|
|
20 |
all_games.extend(games)
|
21 |
return all_games
|
22 |
|
23 |
-
def fetch_and_display_data(
|
24 |
-
|
25 |
-
if
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
else:
|
29 |
-
return "
|
30 |
|
31 |
interface = gr.Interface(
|
32 |
fn=fetch_and_display_data,
|
33 |
-
inputs=
|
34 |
outputs=gr.outputs.DataFrame(),
|
35 |
title="NBA Games Data Fetcher",
|
36 |
-
description="
|
37 |
)
|
38 |
|
39 |
interface.launch()
|
|
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
from datetime import datetime, timedelta
|
5 |
+
import os
|
6 |
|
7 |
def fetch_games_by_date(date, api_key):
|
8 |
url = f"https://api.sportsdata.io/v3/nba/scores/json/GamesByDate/{date}?key={api_key}"
|
|
|
21 |
all_games.extend(games)
|
22 |
return all_games
|
23 |
|
24 |
+
def fetch_and_display_data():
|
25 |
+
api_key = os.getenv('NBA_API_KEY')
|
26 |
+
if api_key:
|
27 |
+
games_data = last_30_days_data(api_key)
|
28 |
+
if games_data:
|
29 |
+
df = pd.DataFrame(games_data)
|
30 |
+
return df
|
31 |
+
else:
|
32 |
+
return "No data available."
|
33 |
else:
|
34 |
+
return "API Key not set."
|
35 |
|
36 |
interface = gr.Interface(
|
37 |
fn=fetch_and_display_data,
|
38 |
+
inputs=[],
|
39 |
outputs=gr.outputs.DataFrame(),
|
40 |
title="NBA Games Data Fetcher",
|
41 |
+
description="Fetches the last 30 days of NBA games data. Make sure your API key is set in the environment variable 'NBA_API_KEY'."
|
42 |
)
|
43 |
|
44 |
interface.launch()
|