correcciones y primer resultado de comentarios con hugo
This commit is contained in:
@@ -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
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -174,5 +174,6 @@ cython_debug/
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
.html
|
||||
.xml
|
||||
*.html
|
||||
*.xml
|
||||
*.md
|
||||
@@ -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"<h3>Remitente: {sender_name}</h3><div>{clean_body}</div>")
|
||||
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)}</div>")
|
||||
|
||||
# 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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user