Aktraiser commited on
Commit
b329fbc
·
verified ·
1 Parent(s): 59111ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -24,25 +24,45 @@ 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
- (Assumes that sport_id 4 corresponds to the NBA.)
28
 
29
  Returns:
30
  A human-readable string listing the upcoming NBA matches.
31
  """
32
- url = "https://api.apilayer.com/therundown/sports/4/events"
 
 
 
 
 
 
 
 
33
  headers = {
34
  "apikey": "7k4hKSUeWkbigKxZiNV5CQ8RSlEd72Cj"
35
  }
 
 
 
 
 
36
 
37
- response = requests.get(url, headers=headers)
38
  if response.status_code == 200:
39
  data = response.json()
40
  matches = []
41
- # Adjust the parsing keys based on the actual API response.
 
42
  for event in data.get("events", []):
43
  start_time = event.get("start_time", "Unknown time")
44
- home_team = event.get("home_team", "Home team not available")
45
- away_team = event.get("away_team", "Away team not available")
 
 
 
 
 
 
46
  matches.append(f"{start_time}: {home_team} vs {away_team}")
47
  if matches:
48
  return "\n".join(matches)
 
24
  def get_nba_matches() -> str:
25
  """
26
  A tool that retrieves upcoming NBA matches using TheRundown API.
27
+ (Assumes that sport-id 4 corresponds to the NBA and uses the "openers" endpoint.)
28
 
29
  Returns:
30
  A human-readable string listing the upcoming NBA matches.
31
  """
32
+ import requests
33
+ import datetime
34
+
35
+ # Get today's date in YYYY-MM-DD format (or adjust to the desired event date)
36
+ today = datetime.date.today().strftime("%Y-%m-%d")
37
+ # Construct the URL using the required parameters.
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}"
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, params=params)
51
  if response.status_code == 200:
52
  data = response.json()
53
  matches = []
54
+ # Ajustez le parsing en fonction de la structure exacte de la réponse.
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
  start_time = event.get("start_time", "Unknown time")
58
+ # Supposons que l'information sur les équipes se trouve dans une liste "teams" avec un attribut "name"
59
+ teams = event.get("teams", [])
60
+ if len(teams) >= 2:
61
+ home_team = teams[0].get("name", "Home team N/A")
62
+ away_team = teams[1].get("name", "Away team N/A")
63
+ else:
64
+ home_team = "Home team N/A"
65
+ away_team = "Away team N/A"
66
  matches.append(f"{start_time}: {home_team} vs {away_team}")
67
  if matches:
68
  return "\n".join(matches)