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_PASS=tu_contraseña_de_aplicacion
|
||||||
IMAP_FOLDER=INBOX
|
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
|
DOMAIN_TO_SEARCH=dominio.com
|
||||||
# Palabras clave a ignorar separadas por coma
|
# Palabras clave a ignorar separadas por coma
|
||||||
IGNORE_KEYWORDS=publicidad,notificacion,spam
|
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
|
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
|
# 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
|
APPEND_HUGO = True
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -174,5 +174,6 @@ cython_debug/
|
|||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
.html
|
*.html
|
||||||
.xml
|
*.xml
|
||||||
|
*.md
|
||||||
@@ -10,6 +10,7 @@ import xml.etree.ElementTree as ET
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from markdownify import markdownify as md
|
from markdownify import markdownify as md
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
@@ -84,9 +85,9 @@ def process_emails():
|
|||||||
|
|
||||||
# --- ACCIONES ---
|
# --- ACCIONES ---
|
||||||
|
|
||||||
# if os.getenv("SAVE_MARKDOWN") == "True":
|
if os.getenv("SAVE_MARKDOWN") == "True":
|
||||||
# with open(f"msg_{m_id.decode()}.html", "w", encoding="utf-8") as f:
|
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>")
|
f.write(f"# Remitente: {sender_name}\n{md(clean_body)}</div>")
|
||||||
|
|
||||||
# HTML: Negritas, cursivas, etc.
|
# HTML: Negritas, cursivas, etc.
|
||||||
if os.getenv("SAVE_HTML") == "True":
|
if os.getenv("SAVE_HTML") == "True":
|
||||||
@@ -121,23 +122,23 @@ def process_emails():
|
|||||||
if os.getenv("APPEND_HUGO") == "True":
|
if os.getenv("APPEND_HUGO") == "True":
|
||||||
with open(f"msg_{m_id.decode()}.md", "w", encoding="utf-8") as f:
|
with open(f"msg_{m_id.decode()}.md", "w", encoding="utf-8") as f:
|
||||||
markdown_text = md(clean_body).strip()
|
markdown_text = md(clean_body).strip()
|
||||||
comment_md = "\n".join([f"> {line}" for line in markdown_text.split("\n")])
|
comment_md = f"\n".join([f">{line}" for line in markdown_text.split("\n")])
|
||||||
parsed_url = urlparse(subject).path.strip("/") #url_path = urlparse(url_absoluta).path.strip("/")
|
parsed_url = urlparse(subject)
|
||||||
ruta_relativa = parsed_url.path + (f"?{parsed_url.query}" if parsed_url.query else "")
|
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")
|
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):
|
if os.path.exists(archivo_md):
|
||||||
with open(archivo_md, "a", encoding="utf-8") as f:
|
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}")
|
print(f"✅ Archivo actualizado en: {archivo_md}")
|
||||||
else:
|
else:
|
||||||
print(f"❌ No se encontró el archivo en {archivo_md}. Verifica la estructura.")
|
print(f"❌ No se encontró el archivo en {archivo_md}. Verifica la estructura.")
|
||||||
|
|
||||||
#f.write(f"## Remitente: {sender_name}\n\n{comment_md}")
|
|
||||||
# Borrar
|
# Borrar
|
||||||
mail.store(m_id, '+FLAGS', '\\Deleted')
|
mail.store(m_id, '+FLAGS', '\\Deleted')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user