-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnose_template.py
More file actions
executable file
·145 lines (117 loc) · 4.91 KB
/
diagnose_template.py
File metadata and controls
executable file
·145 lines (117 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
"""
Diagnostic des templates PPTX
Identifie les problèmes et propose des corrections
"""
from pptx import Presentation
import sys
import os
def diagnose_template(template_path):
if not os.path.exists(template_path):
print(f"❌ Template non trouvé : {template_path}")
return
print(f"\n{'='*60}")
print(f"📊 DIAGNOSTIC DU TEMPLATE : {os.path.basename(template_path)}")
print(f"{'='*60}\n")
prs = Presentation(template_path)
# 1. Statistiques générales
print(f"📄 Nombre de slides : {len(prs.slides)}")
print(f"📐 Taille : {prs.slide_width / 914400:.1f}\" x {prs.slide_height / 914400:.1f}\"\n")
# 2. Analyse des tags texte
print("🏷️ TAGS TEXTE TROUVÉS :")
tags_found = []
for slide_idx, slide in enumerate(prs.slides, 1):
for shape in slide.shapes:
if shape.has_text_frame:
text = shape.text
if "{{" in text and "}}" in text:
# Extraire tous les tags
import re
found_tags = re.findall(r'\{\{([^}]+)\}\}', text)
for tag in found_tags:
tags_found.append((slide_idx, tag, shape.name))
if tags_found:
for slide_idx, tag, shape_name in tags_found:
print(f" Slide {slide_idx} : {{{{{{tag}}}}}}")
else:
print(" ⚠️ Aucun tag trouvé !")
print()
# 3. Analyse des formes nommées (pour images)
print("🖼️ FORMES NOMMÉES (potentiels placeholders d'images) :")
image_placeholders = []
for slide_idx, slide in enumerate(prs.slides, 1):
for shape in slide.shapes:
if "TOP_POST" in shape.name.upper() or "CHART" in shape.name.upper():
image_placeholders.append((slide_idx, shape.name, shape.shape_type))
if image_placeholders:
for slide_idx, name, shape_type in image_placeholders:
print(f" Slide {slide_idx} : {name} (type: {shape_type})")
else:
print(" ⚠️ Aucun placeholder trouvé (TOP_POST_*, CHART_*)")
print()
# 4. Polices utilisées
print("🔤 POLICES UTILISÉES :")
fonts = set()
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
if run.font.name:
fonts.add(run.font.name)
for font in sorted(fonts):
print(f" • {font}")
if "Sofia Pro" not in fonts and "SofiaPro" not in fonts:
print(" ⚠️ Sofia Pro n'est pas utilisée dans ce template")
print()
# 5. Zones de texte potentiellement trop petites
print("⚠️ ZONES DE TEXTE POTENTIELLEMENT TROP PETITES :")
small_shapes = []
for slide_idx, slide in enumerate(prs.slides, 1):
for shape in slide.shapes:
if shape.has_text_frame:
text = shape.text
if len(text) > 20: # Texte long
width_cm = shape.width / 360000
height_cm = shape.height / 360000
if width_cm < 5 or height_cm < 2:
small_shapes.append((slide_idx, text[:30], width_cm, height_cm))
if small_shapes:
for slide_idx, text, w, h in small_shapes[:5]: # Limiter à 5
print(f" Slide {slide_idx} : '{text}...' ({w:.1f}cm x {h:.1f}cm)")
else:
print(" ✅ Toutes les zones semblent correctes")
print()
# 6. Recommandations
print("💡 RECOMMANDATIONS :")
issues = []
if not tags_found:
issues.append("Ajouter des tags {{...}} dans les zones de texte")
if not image_placeholders:
issues.append("Nommer les formes pour images : TOP_POST_INSTAGRAM_1, etc.")
if "Sofia Pro" not in fonts and "SofiaPro" not in fonts:
issues.append("Utiliser Sofia Pro ou l'embedder (Fichier > Options > Enregistrement)")
if small_shapes:
issues.append("Agrandir les zones de texte qui contiennent du texte long")
if issues:
for i, issue in enumerate(issues, 1):
print(f" {i}. {issue}")
else:
print(" ✅ Le template semble correct !")
print(f"\n{'='*60}\n")
# Analyser tous les templates
templates_dir = "templates"
if os.path.exists(templates_dir):
templates = [f for f in os.listdir(templates_dir) if f.endswith('.pptx')]
if len(sys.argv) > 1:
# Template spécifique
template = sys.argv[1]
if not template.endswith('.pptx'):
template += '.pptx'
diagnose_template(os.path.join(templates_dir, template))
else:
# Tous les templates
for template in templates:
diagnose_template(os.path.join(templates_dir, template))
else:
print("❌ Dossier 'templates' introuvable")