Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
+
def fetch_news(topic: str) -> str:
|
38 |
+
"""A tool that fetches news articles based on a given topic."""
|
39 |
+
search_url = f"https://news.google.com/search?q={topic}"
|
40 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
41 |
+
response = requests.get(search_url, headers=headers)
|
42 |
+
|
43 |
+
if response.status_code != 200:
|
44 |
+
return ["Failed to fetch news"]
|
45 |
+
|
46 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
47 |
+
articles = soup.find_all('h3')
|
48 |
+
|
49 |
+
news_list = []
|
50 |
+
for article in articles[:5]: # Fetch top 5 headlines
|
51 |
+
title = article.get_text()
|
52 |
+
link = "https://news.google.com" + article.a['href'][1:] if article.a else ""
|
53 |
+
news_list.append(f"{title} - {link}")
|
54 |
+
|
55 |
+
summary = "\n".join(news_list)
|
56 |
+
|
57 |
+
return summary
|
58 |
+
|
59 |
|
60 |
final_answer = FinalAnswerTool()
|
61 |
|