zvl commited on
Commit
2594bc4
·
verified ·
1 Parent(s): 83c013e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -24,32 +24,29 @@ model = HfApiModel(
24
  @tool
25
  def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
26
  """
27
- Guarda el contenido scrapeado en un archivo Markdown.
28
 
29
- Parámetros:
30
- scraped_data (dict): Diccionario con los siguientes datos:
31
- - url (str): URL de la página web de donde se extrajo el contenido.
32
- - scraped_data (list[str]): Lista de fragmentos de texto extraídos de la página.
33
- filename (str, opcional): Nombre del archivo Markdown a guardar. Si no se proporciona, se generará un nombre automáticamente.
34
-
35
- Retorna:
36
- str: Mensaje indicando si el archivo fue guardado correctamente o si ocurrió un error.
37
  """
38
  try:
39
- url = scraped_data.get("url", "Desconocido")
40
  content_list = scraped_data.get("scraped_data", [])
41
 
42
  if not content_list:
43
- return "No hay datos para guardar en Markdown."
44
 
45
  formatted_content = "\n\n".join(content_list)
46
 
47
- # Estructurar en Markdown
48
- markdown_content = f"# Contenido extraído de {url}\n\n"
49
- markdown_content += "## Contenido Completo\n\n"
50
  markdown_content += formatted_content
51
 
52
- # Generar nombre con timestamp si no se proporciona
53
  if not filename:
54
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
55
  filename = f"scraped_{timestamp}.md"
@@ -57,10 +54,11 @@ def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> s
57
  with open(filename, "w", encoding="utf-8") as file:
58
  file.write(markdown_content)
59
 
60
- return f"El contenido scrapeado se ha guardado en {filename}"
61
 
62
  except Exception as e:
63
- return f"Error al generar el archivo Markdown: {str(e)}"
 
64
 
65
 
66
 
 
24
  @tool
25
  def save_scraped_data_as_markdown(scraped_data: dict, filename: str = None) -> str:
26
  """
27
+ Save scraped content as a well-formatted Markdown file.
28
 
29
+ :param scraped_data: A dictionary containing:
30
+ - url (str): The URL of the webpage from which the content was scraped.
31
+ - scraped_data (list[str]): A list of text fragments extracted from the webpage.
32
+ :param filename: (Optional) The name of the output Markdown file. If not provided, a filename is generated using a timestamp.
33
+ :return: A string message indicating whether the file was saved successfully or an error occurred.
 
 
 
34
  """
35
  try:
36
+ url = scraped_data.get("url", "Unknown")
37
  content_list = scraped_data.get("scraped_data", [])
38
 
39
  if not content_list:
40
+ return "No data available to save in Markdown."
41
 
42
  formatted_content = "\n\n".join(content_list)
43
 
44
+ # Build Markdown content
45
+ markdown_content = f"# Content extracted from {url}\n\n"
46
+ markdown_content += "## Full Content\n\n"
47
  markdown_content += formatted_content
48
 
49
+ # Generate a filename with a timestamp if not provided
50
  if not filename:
51
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
52
  filename = f"scraped_{timestamp}.md"
 
54
  with open(filename, "w", encoding="utf-8") as file:
55
  file.write(markdown_content)
56
 
57
+ return f"Scraped content has been saved in {filename}"
58
 
59
  except Exception as e:
60
+ return f"Error generating Markdown file: {str(e)}"
61
+
62
 
63
 
64