chris-clippd commited on
Commit
89ec470
·
verified ·
1 Parent(s): 4da741c

Added get_team_results tool

Browse files
Files changed (1) hide show
  1. app.py +60 -1
app.py CHANGED
@@ -24,7 +24,7 @@ def get_top_ranked_team(division:str, gender:str)-> dict:
24
  """A tool that returns a dictionary of information (e.g. name, ID, events won etc.) about the top ranked ream for a given division and gender.
25
  Args:
26
  division: A string representing the division. This can only take values from ["NCAA Division I", "NCAA Division II", "NCAA Division III].
27
- gender: A string representing the gender. This can only take vaues from ["Women", "Men"].
28
  """
29
  api_url = f"https://scoreboard.clippd.com/api/rankings/leaderboard?rankingType=Team&gender={gender}&division={division}&sortField=rank&season=2025&limit=1&offset=0"
30
  headers = {
@@ -39,6 +39,65 @@ def get_top_ranked_team(division:str, gender:str)-> dict:
39
  else:
40
  return "Error: Unable to fetch the school."
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str:
44
  """A tool that fetches the current local time in a specified timezone.
 
24
  """A tool that returns a dictionary of information (e.g. name, ID, events won etc.) about the top ranked ream for a given division and gender.
25
  Args:
26
  division: A string representing the division. This can only take values from ["NCAA Division I", "NCAA Division II", "NCAA Division III].
27
+ gender: A string representing the gender. This can only take values from ["Women", "Men"].
28
  """
29
  api_url = f"https://scoreboard.clippd.com/api/rankings/leaderboard?rankingType=Team&gender={gender}&division={division}&sortField=rank&season=2025&limit=1&offset=0"
30
  headers = {
 
39
  else:
40
  return "Error: Unable to fetch the school."
41
 
42
+ @tool
43
+ def get_team_results(school_id: str) -> dict:
44
+ """A tool that returns a dictionary of event results for a team using their school ID.
45
+ Args:
46
+ school_id: A string representing the school's ID.
47
+ """
48
+ # Target URL with dynamic school_id
49
+ url = f"https://scoreboard.clippd.com/teams/{school_id}?season=2025"
50
+
51
+ # Headers to mimic a browser request
52
+ headers = {
53
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
54
+ }
55
+
56
+ # Dictionary to store extracted data
57
+ golf_data = {}
58
+
59
+ # Fetch the raw HTML
60
+ response = requests.get(url, headers=headers)
61
+
62
+ if response.status_code != 200:
63
+ print(f"Failed to retrieve page. Status code: {response.status_code}")
64
+ return golf_data
65
+
66
+ # Parse HTML content
67
+ soup = BeautifulSoup(response.text, "html.parser")
68
+
69
+ # Find the specific table
70
+ table = soup.find("table", {
71
+ "class": "w-full table-auto",
72
+ "data-sentry-component": "InnerTable"
73
+ })
74
+
75
+ if not table:
76
+ print("No table found on the page")
77
+ return golf_data
78
+
79
+ # Find all table rows inside tbody
80
+ table_rows = table.select("tbody tr")
81
+
82
+ for row in table_rows:
83
+ # Extract Event Name
84
+ event_name_tag = row.select_one("td a div div span")
85
+ event_name = event_name_tag.get_text(strip=True) if event_name_tag else ""
86
+
87
+ # Extract Position
88
+ position_tag = row.select_one("td:nth-of-type(2) p")
89
+ position = position_tag.get_text(strip=True) if position_tag else ""
90
+
91
+ # Extract Score
92
+ score_tag = row.select_one("td:nth-of-type(3) div div")
93
+ score = score_tag.get_text(strip=True) if score_tag else ""
94
+
95
+ # Append extracted data to dictionary
96
+ if event_name and position and score:
97
+ golf_data[event_name] = {"Position": position, "Score": score}
98
+
99
+ return golf_data
100
+
101
  @tool
102
  def get_current_time_in_timezone(timezone: str) -> str:
103
  """A tool that fetches the current local time in a specified timezone.