From e9106000614ce9981be999e4dd2336fa288ebb83 Mon Sep 17 00:00:00 2001 From: drk0027 Date: Wed, 14 Jan 2026 23:28:04 -0500 Subject: [PATCH] correcciones y primer resultado de comentarios con hugo --- .env.example | 4 ++-- .gitignore | 5 +++-- email-processor.py | 19 ++++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 2c829a6..8c2d6fa 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ IMAP_USER=tu_correo@gmail.com IMAP_PASS=tu_contraseña_de_aplicacion IMAP_FOLDER=INBOX -# Filtros (el dominio en el asunto debe coincidir con el doominio del blog) +# Filtros (el dominio en el asunto debe coincidir con el dominio del blog) DOMAIN_TO_SEARCH=dominio.com # Palabras clave a ignorar separadas por coma IGNORE_KEYWORDS=publicidad,notificacion,spam @@ -20,5 +20,5 @@ WP_WEBHOOK_URL=https://tusitio.com/wp-json/tudominio/v1/recibir-comentario WEBHOOK_SECRET_TOKEN=mi_clave_secreta_123 # IDEA: vincular a un directorio de HUGO para detectar y acotar los nuevos comentarios como citas en markdown -HUGO_DIR = ../prueba_hugo/ +HUGO_DIR = /home/user/quickstart/ APPEND_HUGO = True \ No newline at end of file diff --git a/.gitignore b/.gitignore index ca6a70b..b339fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -174,5 +174,6 @@ cython_debug/ # PyPI configuration file .pypirc -.html -.xml \ No newline at end of file +*.html +*.xml +*.md \ No newline at end of file diff --git a/email-processor.py b/email-processor.py index 26f2a03..4eb99d5 100644 --- a/email-processor.py +++ b/email-processor.py @@ -10,6 +10,7 @@ import xml.etree.ElementTree as ET from datetime import datetime from markdownify import markdownify as md from urllib.parse import urlparse +from pathlib import Path load_dotenv() @@ -84,9 +85,9 @@ def process_emails(): # --- ACCIONES --- - # if os.getenv("SAVE_MARKDOWN") == "True": - # with open(f"msg_{m_id.decode()}.html", "w", encoding="utf-8") as f: - # f.write(f"

Remitente: {sender_name}

{clean_body}
") + if os.getenv("SAVE_MARKDOWN") == "True": + with open(f"msg_{m_id.decode()}.html", "w", encoding="utf-8") as f: + f.write(f"# Remitente: {sender_name}\n{md(clean_body)}") # HTML: Negritas, cursivas, etc. if os.getenv("SAVE_HTML") == "True": @@ -121,23 +122,23 @@ def process_emails(): if os.getenv("APPEND_HUGO") == "True": with open(f"msg_{m_id.decode()}.md", "w", encoding="utf-8") as f: markdown_text = md(clean_body).strip() - comment_md = "\n".join([f"> {line}" for line in markdown_text.split("\n")]) - parsed_url = urlparse(subject).path.strip("/") #url_path = urlparse(url_absoluta).path.strip("/") + comment_md = f"\n".join([f">{line}" for line in markdown_text.split("\n")]) + parsed_url = urlparse(subject) ruta_relativa = parsed_url.path + (f"?{parsed_url.query}" if parsed_url.query else "") + p = Path(ruta_relativa.lstrip("/")) hugo_dir = os.getenv("HUGO_DIR") - directorio_destino = os.path.join(base_hugo_path, "content", ruta_relativa) + directorio_destino = os.path.join(hugo_dir+"content",p.parent) - archivo_md = os.path.join(directorio_destino, "index.md") + archivo_md = os.path.join(directorio_destino, p.name + ".md") if os.path.exists(archivo_md): with open(archivo_md, "a", encoding="utf-8") as f: - f.write(f"\n\n> {comment_md}.") + f.write(f"\n\n## {sender_name} dice:\n{comment_md}.") print(f"✅ Archivo actualizado en: {archivo_md}") else: print(f"❌ No se encontró el archivo en {archivo_md}. Verifica la estructura.") - #f.write(f"## Remitente: {sender_name}\n\n{comment_md}") # Borrar mail.store(m_id, '+FLAGS', '\\Deleted')