Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,39 +43,29 @@ def get_random_joke() -> str:
|
|
| 43 |
@tool
|
| 44 |
def question_about_car_km77(query: str) -> str:
|
| 45 |
"""
|
| 46 |
-
A tool that queries https://www.km77.com/
|
| 47 |
-
|
| 48 |
-
|
| 49 |
Args:
|
| 50 |
-
query (str): The
|
| 51 |
-
|
| 52 |
-
Returns:
|
| 53 |
-
str: A short text containing top search results or an error message if none are found.
|
| 54 |
"""
|
| 55 |
try:
|
| 56 |
-
# Hacemos una búsqueda en la sección del buscador de km77
|
| 57 |
search_url = f"https://www.km77.com/buscador/?q={query}"
|
| 58 |
response = requests.get(search_url, timeout=10)
|
| 59 |
|
| 60 |
if response.status_code != 200:
|
| 61 |
return f"Error accediendo a km77. Código de estado HTTP: {response.status_code}"
|
| 62 |
|
| 63 |
-
# Usamos BeautifulSoup para parsear el HTML
|
| 64 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 65 |
|
| 66 |
-
# Seleccionamos algunos enlaces de la página de resultados
|
| 67 |
-
# (el selector CSS podría variar si km77 cambia su estructura)
|
| 68 |
results = soup.select("div.col-xs-12.col-md-8 a")
|
| 69 |
if not results:
|
| 70 |
return "No se encontraron resultados para tu búsqueda en km77."
|
| 71 |
|
| 72 |
-
# Tomamos los primeros 5 resultados y construimos una respuesta
|
| 73 |
answer_lines = []
|
| 74 |
for r in results[:5]:
|
| 75 |
-
title = r.get_text(strip=True)
|
| 76 |
-
link = r.get(
|
| 77 |
if link.startswith('/'):
|
| 78 |
-
# Ajustar link relativo al dominio principal
|
| 79 |
link = f"https://www.km77.com{link}"
|
| 80 |
answer_lines.append(f"- {title}: {link}")
|
| 81 |
|
|
|
|
| 43 |
@tool
|
| 44 |
def question_about_car_km77(query: str) -> str:
|
| 45 |
"""
|
| 46 |
+
A tool that queries https://www.km77.com/ for information about a specific car or topic.
|
| 47 |
+
|
|
|
|
| 48 |
Args:
|
| 49 |
+
query (str): The keywords or phrase to search for on km77.
|
|
|
|
|
|
|
|
|
|
| 50 |
"""
|
| 51 |
try:
|
|
|
|
| 52 |
search_url = f"https://www.km77.com/buscador/?q={query}"
|
| 53 |
response = requests.get(search_url, timeout=10)
|
| 54 |
|
| 55 |
if response.status_code != 200:
|
| 56 |
return f"Error accediendo a km77. Código de estado HTTP: {response.status_code}"
|
| 57 |
|
|
|
|
| 58 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 59 |
|
|
|
|
|
|
|
| 60 |
results = soup.select("div.col-xs-12.col-md-8 a")
|
| 61 |
if not results:
|
| 62 |
return "No se encontraron resultados para tu búsqueda en km77."
|
| 63 |
|
|
|
|
| 64 |
answer_lines = []
|
| 65 |
for r in results[:5]:
|
| 66 |
+
title = r.get_text(strip=True)
|
| 67 |
+
link = r.get("href")
|
| 68 |
if link.startswith('/'):
|
|
|
|
| 69 |
link = f"https://www.km77.com{link}"
|
| 70 |
answer_lines.append(f"- {title}: {link}")
|
| 71 |
|