Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,21 +24,36 @@ def fetch_marathon_plan(goal_time: str) -> str:
|
|
| 24 |
else:
|
| 25 |
return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
|
| 26 |
|
|
|
|
| 27 |
@tool
|
| 28 |
def fetch_european_marathons_2025() -> str:
|
| 29 |
-
"""Fetches a list of marathons in Europe
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
"""
|
| 34 |
-
search_tool = DuckDuckGoSearchTool()
|
| 35 |
-
query = "marathons in Europe 2025 site:marathonrunnersdiary.com"
|
| 36 |
-
results = search_tool.search(query)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
else:
|
| 41 |
-
return "
|
| 42 |
|
| 43 |
final_answer = FinalAnswerTool()
|
| 44 |
|
|
|
|
| 24 |
else:
|
| 25 |
return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
|
| 26 |
|
| 27 |
+
# Fetch marathons in Europe for 2025
|
| 28 |
@tool
|
| 29 |
def fetch_european_marathons_2025() -> str:
|
| 30 |
+
"""Fetches a list of marathons in Europe in 2025 from MarathonRunnersDiary."""
|
| 31 |
+
url = "http://www.marathonrunnersdiary.com/races/europe-marathons-list.php"
|
| 32 |
+
response = requests.get(url)
|
| 33 |
|
| 34 |
+
if response.status_code != 200:
|
| 35 |
+
return "Failed to fetch marathon data."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 38 |
+
|
| 39 |
+
# Locate the marathon table (this is based on the structure of the website)
|
| 40 |
+
marathons = []
|
| 41 |
+
table = soup.find('table', {'class': 'racedatatable'}) # Adjust the class if necessary
|
| 42 |
+
|
| 43 |
+
if table:
|
| 44 |
+
rows = table.find_all('tr')[1:] # Skip the header row
|
| 45 |
+
for row in rows:
|
| 46 |
+
columns = row.find_all('td')
|
| 47 |
+
if len(columns) >= 4:
|
| 48 |
+
marathon_name = columns[0].get_text(strip=True)
|
| 49 |
+
marathon_date = columns[1].get_text(strip=True)
|
| 50 |
+
marathon_location = columns[2].get_text(strip=True)
|
| 51 |
+
marathons.append(f"{marathon_name} on {marathon_date} in {marathon_location}")
|
| 52 |
+
|
| 53 |
+
if marathons:
|
| 54 |
+
return "\n".join(marathons)
|
| 55 |
else:
|
| 56 |
+
return "No marathons found for 2025."
|
| 57 |
|
| 58 |
final_answer = FinalAnswerTool()
|
| 59 |
|