File size: 7,155 Bytes
62f88b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
from smolagents import tool
import requests
import os
from dotenv import load_dotenv

load_dotenv()

headers = {
	"x-rapidapi-key": os.getenv("RAPID_API_KEY"),
	"x-rapidapi-host": "free-api-live-football-data.p.rapidapi.com"
}

@tool 
def get_pl_standings() -> dict: # return the current Premier League standings
    """A tool that returns the current Premier League standings.

    Args:

        None

    Returns:

        The current Premier League standings in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-standing-all"

    querystring = {"leagueid":"47"}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_matches_by_date(date:str) -> dict: # return all matches in the current Premier League season by date
    """A tool that returns all matches in the current Premier League season by date.

    Args:

        date: The date in the format 'YYYYMMDD'.

    Returns:

        All matches in the current Premier League season by date in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-matches-by-date"

    querystring = {"date": date}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_head_to_head(eventid: str) -> dict: #return head to head records by the event (match) id
    """A tool that returns the head to head records by the event (match) id.

    Args:

        eventid: The event (match) id.

    Returns:

        The head to head records in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-head-to-head"

    querystring = {"eventid": eventid}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool 
def get_all_teams() -> dict:
    """A tool that returns all teams in the Premier League.

    Args:

        None

    Returns:

        All teams in the Premier League in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-list-all-team"

    querystring = {"leagueid":"47"}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool 
def get_all_players_by_team(teamid: str) -> dict:
    """A tool that returns all players by team.

    Args:

        teamid: The team id.

    Returns:

        All players by team in JSON.

    """

    url = "hhttps://free-api-live-football-data.p.rapidapi.com/football-get-list-player"

    querystring = {"teamid": teamid}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_player_details_by_id(playerid: str) -> dict:
    """A tool that returns player details by player id.

    Args:

        playerid: The player id.

    Returns:

        Player details in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-player-detail"

    querystring = {"playerid": playerid}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_home_lineup(eventid: str) -> dict: 
    """A tool that returns the home team lineup by event (match) id.

    Args:

        eventid: The event (match) id.

    Returns:

        The home team lineup in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-hometeam-lineup"

    querystring = {"eventid": eventid}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_away_lineup(eventid: str) -> dict:
    """A tool that returns the away team lineup by event (match) id.

    Args:

        eventid: The event (match) id.

    Returns:

        The away team lineup in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-awayteam-lineup"

    querystring = {"eventid": eventid}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_top_goalscorers() -> dict:
    """A tool that returns the top goalscorers in the Premier League.

    Args:

        None

    Returns:

        The top goalscorers in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-top-players-by-goals"

    querystring = {"leagueid":"47"}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_top_assisters() -> dict:
    """A tool that returns the top assisters in the Premier League.

    Args:

        None

    Returns:

        The top assisters in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-top-players-by-assists"

    querystring = {"leagueid":"47"}

    try:        
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"

@tool
def get_top_rated_players() -> dict:
    """A tool that returns the top rated players in the Premier League.

    Args:

        None

    Returns:

        The top rated players in JSON.

    """

    url = "https://free-api-live-football-data.p.rapidapi.com/football-get-top-players-by-rating"

    querystring = {"leagueid":"47"}

    try:
        response = requests.get(url, headers=headers, params=querystring)
        response.raise_for_status()
        return response.json()
    except Exception as e:
        return f"Error fetching Premier League standings: {str(e)}"