robertgil commited on
Commit
6aa9465
·
verified ·
1 Parent(s): cc1fa82

enhanced response

Browse files
Files changed (1) hide show
  1. app.py +52 -3
app.py CHANGED
@@ -28,10 +28,59 @@ def get_football_results(arg1:str, arg2:str)-> str: #it's import to specify the
28
  "x-rapidapi-key": rapid_api_key,
29
  "x-rapidapi-host": "free-api-live-football-data.p.rapidapi.com"
30
  }
31
-
32
- response = requests.get(url, headers=headers, params=querystring)
33
 
34
- return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str:
 
28
  "x-rapidapi-key": rapid_api_key,
29
  "x-rapidapi-host": "free-api-live-football-data.p.rapidapi.com"
30
  }
 
 
31
 
32
+ try:
33
+ response = requests.get(url, headers=headers, params=querystring)
34
+ response.raise_for_status() # Raise exception for bad responses
35
+
36
+ data = response.json()
37
+
38
+ # Extract standings data from response
39
+ standings = data.get('standing', [])
40
+
41
+ # Find the data for both requested teams
42
+ team1_data = None
43
+ team2_data = None
44
+
45
+ for team in standings:
46
+ if team1.lower() in team.get('team_name', '').lower():
47
+ team1_data = team
48
+ if team2.lower() in team.get('team_name', '').lower():
49
+ team2_data = team
50
+
51
+ # Generate the comparison text
52
+ if team1_data and team2_data:
53
+ comparison = f"## {team1_data['team_name']} vs {team2_data['team_name']} Comparison\n\n"
54
+ comparison += f"### {team1_data['team_name']}:\n"
55
+ comparison += f"- Position: {team1_data.get('place', 'N/A')}\n"
56
+ comparison += f"- Matches Played: {team1_data.get('played', 'N/A')}\n"
57
+ comparison += f"- Wins: {team1_data.get('win', 'N/A')}\n"
58
+ comparison += f"- Draws: {team1_data.get('draw', 'N/A')}\n"
59
+ comparison += f"- Losses: {team1_data.get('loss', 'N/A')}\n"
60
+ comparison += f"- Goals For: {team1_data.get('goals_for', 'N/A')}\n"
61
+ comparison += f"- Goals Against: {team1_data.get('goals_against', 'N/A')}\n"
62
+ comparison += f"- Points: {team1_data.get('points', 'N/A')}\n\n"
63
+
64
+ comparison += f"### {team2_data['team_name']}:\n"
65
+ comparison += f"- Position: {team2_data.get('place', 'N/A')}\n"
66
+ comparison += f"- Matches Played: {team2_data.get('played', 'N/A')}\n"
67
+ comparison += f"- Wins: {team2_data.get('win', 'N/A')}\n"
68
+ comparison += f"- Draws: {team2_data.get('draw', 'N/A')}\n"
69
+ comparison += f"- Losses: {team2_data.get('loss', 'N/A')}\n"
70
+ comparison += f"- Goals For: {team2_data.get('goals_for', 'N/A')}\n"
71
+ comparison += f"- Goals Against: {team2_data.get('goals_against', 'N/A')}\n"
72
+ comparison += f"- Points: {team2_data.get('points', 'N/A')}\n"
73
+
74
+ return comparison
75
+ elif not team1_data and not team2_data:
76
+ return f"Could not find data for either {team1} or {team2} in the Premier League standings."
77
+ elif not team1_data:
78
+ return f"Could not find data for {team1} in the Premier League standings."
79
+ else:
80
+ return f"Could not find data for {team2} in the Premier League standings."
81
+
82
+ except Exception as e:
83
+ return f"Error retrieving or processing football data: {str(e)}"
84
 
85
  @tool
86
  def get_current_time_in_timezone(timezone: str) -> str: