Spaces:
Sleeping
Sleeping
added a clickable link
Browse files18 unmodified lines192021222324252627282927 unmodified lines5758596061626364656667686970717273747518 unmodified linesarg2: the second argument"""return "What magic will you build ?"@tooldef get_philippines_news(query: str = None, max_results: int = 5) -> str:"""Fetches latest Philippines news from Google NewsArgs:query: Optional search query to filter newsmax_results: Number of results to return (1-10)27 unmodified linesformatted_news = []for idx, article in enumerate(articles, 1):# Try to extract title and sourcetitle_element = article.find('a', class_='JtKRv')source_element = article.find('div', class_='vr1PYe')title = title_element.text.strip() if title_element else "No title"source = source_element.text.strip() if source_element else "Unknown source"formatted_news.append(f"{idx}. {title} - {source}")return "\n".join(formatted_news[:max_results])except Exception as e:return f"Error fetching news: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:18 unmodified lines192021222324252627282927 unmodified lines5758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313418 unmodified linesarg2: the second argument"""return "What magic will you build ?"from urllib.parse import urljoin@tooldef get_philippines_news(query: str = None, max_results: int = 5) -> str:"""Fetches latest Philippines news from Google News with clickable linksArgs:query: Optional search query to filter newsmax_results: Number of results to return (1-10)27 unmodified linesformatted_news = []for idx, article in enumerate(articles, 1):# Extract article componentstitle_element = article.find('a', class_='JtKRv')source_element = article.find('div', class_='vr1PYe')title = title_element.text.strip() if title_element else "No title"source = source_element.text.strip() if source_element else "Unknown source"# Build clickable linkrelative_link = title_element.get('href', '') if title_element else ''full_link = urljoin(base_url, relative_link) if relative_link else ''formatted_entry = (f"{idx}. <a href='{full_link}' target='_blank'>{title}</a> - {source}"if full_linkelse f"{idx}. {title} - {source}")formatted_news.append(formatted_entry)return "\n".join(formatted_news[:max_results])except Exception as e:return f"Error fetching news: {str(e)}"# @tool# def get_philippines_news(query: str = None, max_results: int = 5) -> str:# """Fetches latest Philippines news from Google News# Args:# query: Optional search query to filter news# max_results: Number of results to return (1-10)# """# try:# headers = {# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"# }# base_url = "https://news.google.com"# params = {# "hl": "en-PH",# "gl": "PH",# "ceid": "PH:en"# }# if query:# params["q"] = query# url = f"{base_url}/search"# else:# url = f"{base_url}/topics/CAAqJggKIiBDQkFTRWdvSUwyMHZNRFpxYUdjU0FtVnVHZ0pWVXlnQVAB?hl=en-PH&gl=PH&ceid=PH%3Aen"# response = requests.get(url, params=params, headers=headers)# response.raise_for_status()# soup = BeautifulSoup(response.content, 'html.parser')# articles = soup.find_all('article')[:max_results]# if not articles:# return "No news articles found"# formatted_news = []# for idx, article in enumerate(articles, 1):# # Try to extract title and source# title_element = article.find('a', class_='JtKRv')# source_element = article.find('div', class_='vr1PYe')# title = title_element.text.strip() if title_element else "No title"# source = source_element.text.strip() if source_element else "Unknown source"# formatted_news.append(f"{idx}. {title} - {source}")# return "\n".join(formatted_news[:max_results])# except Exception as e:# return f"Error fetching news: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:
app.py+63-4