import json import sys from datetime import datetime from pathlib import Path from loader import load_json_data from pdf_builder import generate_pdf def get_tags() -> str: """Récupère les tags ATS ou interagit avec l'utilisateur si absent.""" tag_file = Path(__file__).parent / "data" / "tag_stuff.json" if not tag_file.exists(): print("\n⚠️ [ATTENTION] Le fichier 'data/tag_stuff.json' est introuvable.") print("Il est utilisé pour le tag stuffing (IA/ATS).") choice = input("Voulez-vous poursuivre la génération SANS le tag stuffing ? (o/N) : ").strip().lower() if choice not in ['o', 'oui']: print("Génération annulée par l'utilisateur.") sys.exit(0) return "" try: with open(tag_file, "r", encoding="utf-8") as f: content = json.load(f) return content.get("tags", "") except Exception as e: print(f"❌ Erreur lors de la lecture de tag_stuff.json : {e}") sys.exit(1) def main(): try: data = load_json_data() except Exception as e: print(f"❌ Erreur lors du chargement des données : {e}") return # Vérification et récupération des tags tags = get_tags() export_dir = Path(__file__).parent / "exports" export_dir.mkdir(exist_ok=True) timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") title_raw = data.get("context", {}).get("title", "CV") title_clean = "".join(c if c.isalnum() else "_" for c in title_raw) filename = f"{timestamp}_{title_clean}.pdf" output_path = export_dir / filename generate_pdf(data, tags, str(output_path)) if __name__ == "__main__": main()