Skip to content

Commit f32a69f

Browse files
committed
Ajout d'une option pour définir la longueur minimale du texte dans le script de génération HTML
refs #3
1 parent 97120c8 commit f32a69f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
- name: Run build script
3030
run: |
31-
pipenv run python scripts/build.py
31+
pipenv run python scripts/build.py --min-text-length=${vars.MIN_TEXT_LENGTH}
3232
3333
- name: Commit and push changes
3434
run: |

scripts/build.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import json
22
import random
3-
3+
import argparse
44
from jinja2 import Environment, FileSystemLoader
55

6+
# Configurer les arguments de ligne de commande
7+
parser = argparse.ArgumentParser(description='Générer un fichier HTML à partir d\'un modèle et de données JSON.')
8+
parser.add_argument('--min-text-length', type=int, help='Longueur minimale du texte choisi', default=0)
9+
args = parser.parse_args()
10+
611
# Charger les données JSON
712
with open("./docs/manifest.json", "r", encoding="utf-8") as f:
813
data = json.load(f)
914

15+
# Filtrer les textes en fonction de la longueur minimale
16+
filtered_texts = [text for text in data["texts"] if len(text) >= args.min_text_length]
17+
1018
# Sélectionner un texte, une image et un audio au hasard
11-
text = random.choice(data["texts"])
19+
if filtered_texts:
20+
text = random.choice(filtered_texts)
21+
else:
22+
print(f"Aucun texte ne correspond à la longueur minimale de {args.min_text_length} caractères.")
23+
exit(1)
24+
1225
image = random.choice(data["images"])
1326
audio = random.choice(data["audios"])
1427

0 commit comments

Comments
 (0)