Spaces:
Sleeping
Sleeping
| 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" | |
| } | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |
| 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)}" | |