Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
24 |
def get_nba_matches() -> str:
|
25 |
"""
|
26 |
A tool that retrieves upcoming NBA matches using TheRundown API.
|
27 |
-
|
28 |
|
29 |
Returns:
|
30 |
A human-readable string listing the upcoming NBA matches.
|
@@ -32,38 +32,30 @@ def get_nba_matches() -> str:
|
|
32 |
import requests
|
33 |
import datetime
|
34 |
|
35 |
-
#
|
36 |
today = datetime.date.today().strftime("%Y-%m-%d")
|
37 |
-
#
|
38 |
-
# Based on the API info, the URL should include the sport-id (here 4 for NBA) and the event date.
|
39 |
url = f"https://api.apilayer.com/therundown/sports/4/openers/{today}?offset=0&include=scores"
|
40 |
|
41 |
headers = {
|
42 |
"apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
|
43 |
}
|
44 |
-
# Define query parameters if needed; here on fixe offset à 0 et on demande par exemple les scores (optionnel)
|
45 |
-
params = {
|
46 |
-
"offset": "0",
|
47 |
-
"include": "scores"
|
48 |
-
}
|
49 |
|
50 |
-
response = requests.get(url, headers=headers
|
51 |
if response.status_code == 200:
|
52 |
data = response.json()
|
53 |
matches = []
|
54 |
-
#
|
55 |
-
# Par exemple, nous supposons que la réponse contient une clé "events" qui liste les matchs.
|
56 |
for event in data.get("events", []):
|
57 |
-
|
58 |
-
|
59 |
teams = event.get("teams", [])
|
60 |
if len(teams) >= 2:
|
61 |
-
|
62 |
-
|
63 |
else:
|
64 |
-
|
65 |
-
|
66 |
-
matches.append(f"{start_time}: {home_team} vs {away_team}")
|
67 |
if matches:
|
68 |
return "\n".join(matches)
|
69 |
else:
|
|
|
24 |
def get_nba_matches() -> str:
|
25 |
"""
|
26 |
A tool that retrieves upcoming NBA matches using TheRundown API.
|
27 |
+
Uses the /openers endpoint for the specified date.
|
28 |
|
29 |
Returns:
|
30 |
A human-readable string listing the upcoming NBA matches.
|
|
|
32 |
import requests
|
33 |
import datetime
|
34 |
|
35 |
+
# Utilisez la date d'aujourd'hui ou une date spécifique
|
36 |
today = datetime.date.today().strftime("%Y-%m-%d")
|
37 |
+
# Construisez l'URL avec des paramètres corrects (ici offset=0 et include=scores)
|
|
|
38 |
url = f"https://api.apilayer.com/therundown/sports/4/openers/{today}?offset=0&include=scores"
|
39 |
|
40 |
headers = {
|
41 |
"apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
|
42 |
}
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
response = requests.get(url, headers=headers)
|
45 |
if response.status_code == 200:
|
46 |
data = response.json()
|
47 |
matches = []
|
48 |
+
# Parcourez la liste des événements retournés par l'API
|
|
|
49 |
for event in data.get("events", []):
|
50 |
+
# Utilisez la clé "event_date" au lieu de "start_time"
|
51 |
+
event_date = event.get("event_date", "Unknown date")
|
52 |
teams = event.get("teams", [])
|
53 |
if len(teams) >= 2:
|
54 |
+
team1 = teams[0].get("name", "Team1 N/A")
|
55 |
+
team2 = teams[1].get("name", "Team2 N/A")
|
56 |
else:
|
57 |
+
team1, team2 = "Team1 N/A", "Team2 N/A"
|
58 |
+
matches.append(f"{event_date}: {team1} vs {team2}")
|
|
|
59 |
if matches:
|
60 |
return "\n".join(matches)
|
61 |
else:
|