mirror of
https://forge.chapril.org/tykayn/book_generator
synced 2025-06-20 01:34:43 +02:00
init avec readme
This commit is contained in:
commit
60bc5ca9d0
26 changed files with 1955 additions and 0 deletions
56
stats_chapitres.py
Normal file
56
stats_chapitres.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
regex_chapitre = r'\*\* (.+)'
|
||||
fichier_livre = 'livre.org'
|
||||
|
||||
# Ouvrir le fichier livre.org
|
||||
with open("livre.org", "r") as livre:
|
||||
content = livre.read()
|
||||
|
||||
# Définir la fonction pour séparer les mots d'une ligne
|
||||
def split_words(line):
|
||||
return re.split('[\s]+', line)
|
||||
|
||||
# Initialisation du dictionnaire pour stocker le nombre de mots par chapitre
|
||||
chapters_word_count = defaultdict(int)
|
||||
|
||||
# Parcours des lignes du fichier
|
||||
# Parcourir chaque ligne du fichier livre.org
|
||||
chapitre = '(chapitre not found)'
|
||||
for ligne in content.strip().split("\n"):
|
||||
# Rechercher le titre du chapitre
|
||||
match_chapitre = re.search(regex_chapitre, ligne)
|
||||
if match_chapitre:
|
||||
chapitre = re.sub( ":title:", "", match_chapitre.group(1))
|
||||
print(chapitre)
|
||||
words = split_words(ligne)
|
||||
chapters_word_count[chapitre] += len(words)
|
||||
|
||||
|
||||
def draw_progress_bar(percent: float, target: int) -> str:
|
||||
# Calcul du nombre total de caractères nécessaire pour représenter 100%
|
||||
max_length = len("█") * (target / 100)
|
||||
|
||||
# Calcul de la longueur de la barre de progression
|
||||
length = int((max_length * percent) // 100)
|
||||
|
||||
# Création de la chaîne représentant la barre de progression
|
||||
progress_bar = "[" + ("█" * int(length)) + ("_" * (int(max_length) - int(length))) + "]"
|
||||
|
||||
# Affichage de la barre de progression
|
||||
# print(f"\rProgression : {percent}%, {progress_bar}", end="\r")
|
||||
|
||||
return progress_bar
|
||||
|
||||
objectif_mots=500
|
||||
sum_mots=0
|
||||
# Afficher le résultat
|
||||
print("Nombre de mots par chapitre : ")
|
||||
count_chapitres=0
|
||||
for count, value in sorted(chapters_word_count.items(), key=lambda item: item[0]):
|
||||
sum_mots+=value
|
||||
count_chapitres+=1
|
||||
print(f"{value} mots \t\t \t{count} \t\t{draw_progress_bar(value, objectif_mots)} \t\t ")
|
||||
print(f"\n Total : \n\t {sum_mots} mots.\n\t {count_chapitres} chapitres.")
|
Loading…
Add table
Add a link
Reference in a new issue