64 lines
2.5 KiB
Python
64 lines
2.5 KiB
Python
|
|
"""
|
||
|
|
trilium_logger.py — Intégration pipeline Sliding Automation
|
||
|
|
À appeler depuis facilitator.py pour logger chaque génération automatiquement.
|
||
|
|
|
||
|
|
Usage depuis facilitator.py :
|
||
|
|
from trilium_logger import log_session
|
||
|
|
log_session("Mon titre", nb_slides=12, yaml_path="output/x.yaml",
|
||
|
|
pptx_path="output/x.pptx", layouts=["cover_split", "big_stat"])
|
||
|
|
"""
|
||
|
|
import os
|
||
|
|
from datetime import datetime
|
||
|
|
from dotenv import load_dotenv
|
||
|
|
|
||
|
|
load_dotenv()
|
||
|
|
|
||
|
|
# Import relatif — suppose que trilium_logger.py est dans le même dossier
|
||
|
|
# que trilium_api.py, ou que le chemin est dans PYTHONPATH
|
||
|
|
import sys
|
||
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
||
|
|
from trilium_api import create_note, set_label, find_note_by_title
|
||
|
|
|
||
|
|
TRILIUM_URL = os.getenv("TRILIUM_URL", "http://localhost:4292")
|
||
|
|
DEFAULT_PROJ = os.getenv("DEFAULT_PROJECT", "SlidingAutomation")
|
||
|
|
|
||
|
|
# ID du dossier Sessions dans Sliding Pipeline (à renseigner après init)
|
||
|
|
# Récupérable via : python trilium_init.py --show-ids
|
||
|
|
SESSIONS_PARENT_ID = os.getenv("TRILIUM_SESSIONS_ID", "")
|
||
|
|
|
||
|
|
def log_session(titre: str, nb_slides: int, yaml_path: str, pptx_path: str,
|
||
|
|
layouts: list = None, projet: str = None):
|
||
|
|
"""
|
||
|
|
Crée une note de session dans Trilium.
|
||
|
|
Appelé automatiquement par facilitator.py en fin de génération.
|
||
|
|
"""
|
||
|
|
if not SESSIONS_PARENT_ID:
|
||
|
|
print(" ⚠ TRILIUM_SESSIONS_ID non défini dans .env — log ignoré")
|
||
|
|
return
|
||
|
|
|
||
|
|
projet = projet or DEFAULT_PROJ
|
||
|
|
date = datetime.now().strftime("%Y-%m-%d %H:%M")
|
||
|
|
layouts_str = ", ".join(layouts) if layouts else "non renseignés"
|
||
|
|
|
||
|
|
content = f"""<h2>Session {date}</h2>
|
||
|
|
<table>
|
||
|
|
<tr><td><b>Titre</b></td><td>{titre}</td></tr>
|
||
|
|
<tr><td><b>Slides</b></td><td>{nb_slides}</td></tr>
|
||
|
|
<tr><td><b>YAML</b></td><td>{yaml_path}</td></tr>
|
||
|
|
<tr><td><b>PPTX</b></td><td>{pptx_path}</td></tr>
|
||
|
|
<tr><td><b>Layouts</b></td><td>{layouts_str}</td></tr>
|
||
|
|
<tr><td><b>Date</b></td><td>{date}</td></tr>
|
||
|
|
</table>"""
|
||
|
|
|
||
|
|
try:
|
||
|
|
result = create_note(SESSIONS_PARENT_ID, f"Session {date} — {titre}", content)
|
||
|
|
note_id = result["note"]["noteId"]
|
||
|
|
set_label(note_id, "type", "sessionSliding")
|
||
|
|
set_label(note_id, "projet", projet)
|
||
|
|
set_label(note_id, "nbSlides", str(nb_slides))
|
||
|
|
set_label(note_id, "yamlPath", yaml_path)
|
||
|
|
set_label(note_id, "pptxPath", pptx_path)
|
||
|
|
set_label(note_id, "layouts", layouts_str)
|
||
|
|
print(f" ✓ Session loggée dans Trilium : {titre} (ID: {note_id})")
|
||
|
|
except Exception as e:
|
||
|
|
print(f" ⚠ Trilium log failed : {e}")
|