mirror of
https://forge.chapril.org/tykayn/book_generator
synced 2025-06-20 01:34:43 +02:00
add install & TOC script, BD illus models
This commit is contained in:
parent
f4cea3ac08
commit
caee997e01
56 changed files with 2418 additions and 4 deletions
41
BD/omg_la_bd/scenario/drawing_psd_generator.sh
Normal file
41
BD/omg_la_bd/scenario/drawing_psd_generator.sh
Normal file
|
@ -0,0 +1,41 @@
|
|||
https://tykayn.fr/2019/un-plan-de-calques-pour-planche-de-bd/
|
||||
|
||||
|
||||
maBDomgWOW
|
||||
|---- chapitres
|
||||
| |---- 01
|
||||
| |---- 02
|
||||
|----- docs_preparatoires
|
||||
| |---- fiches_perso
|
||||
| |---- scenario
|
||||
| |---- inspiration
|
||||
| |---- typo
|
||||
|---- fanarts (hé ouais!)
|
||||
|---- livres
|
||||
|
||||
Ensuite, faire un ensemble de dossiers pour CHAQUE chapitre de BD:
|
||||
|
||||
bonus : conneries diverses que l’on peut mettre en dehors des chapitres de notre BD, retapages de cases en changeant le texte, tout ça…
|
||||
|
||||
découpage : essais de mise en page miniatures, afin d’avoir une vue globale de notre chapitre, et des ruptures entre doubles pages pour ménager le suspens et la dynamique de lecture.
|
||||
|
||||
rendus : pages finies, en haute définition, prêtes à être imprimées, que l’on peut insérer dans un fichier de livre. inclut aussi la page de résumé des chapitres précédents et une fiche de personnages. nommées sobrement par page de chapitre et non du livre: 01.png, 02.png, etc…
|
||||
|
||||
ressources : placer ici ses trouvailles de recherches d’inspiration diverses relatives à notre chapitre, photos, pages web, vidéos, peintures, musique… mais aussi des assets à utiliser dans les planches, comme des motifs, des textures, des fichiers vetoriels pour inclure des logos.
|
||||
|
||||
scans : comme je fais mes traits d’abord sur papier à coup de criterium, je les scanne en grosse définition et les mets dans un dossier dédié.
|
||||
|
||||
textes : les dialogues et autres textes à insérer dans les pages.
|
||||
|
||||
wip : fichiers de travail disposant de calques ayant pour base les scans. Les scripts données plus haut s’appliquent par ici.
|
||||
|
||||
|
||||
mkdir -p maBDomgWOW maBDomgWOW/chapitres/01 docs_preparatoires/fiches_perso docs_preparatoires/scenario docs_preparatoires/inspiration docs_preparatoires/typo livres fanarts
|
||||
|
||||
cd maBDomgWOW/chapitres/01
|
||||
|
||||
mkdir bonus découpage rendus ressources scans textes wip
|
||||
|
||||
cd ..
|
||||
|
||||
cp -r 01 02
|
3
BD/omg_la_bd/scenario/export_script.sh
Normal file
3
BD/omg_la_bd/scenario/export_script.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
emacs --batch --eval "(require 'org)" --eval "(org-export-as-html \"livre.org\" \"livre.html\")"
|
63
BD/omg_la_bd/scenario/find_characters_in_book.py
Normal file
63
BD/omg_la_bd/scenario/find_characters_in_book.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
# prend le fichier personnages.org, détermine les noms des personnages selon les entêtes orgmode, et va ensuite lire le fichier livre.org et parcourir ses entêtes qui sont les chapitres du livre.
|
||||
# générer un fichier csv qui listera les chapitres et les personnages en colonnes, pour compter 1 à chaque chapitre lorsque le nom du personnage est retrouvé dedans
|
||||
# les personnages que l'on recherche dans le livre ne sont pas mentionnés dans la ligne d'entête; mais dans les lignes entre deux entêtes, dans les corps de texte
|
||||
import csv
|
||||
import re
|
||||
|
||||
# Remplacer par les chemins vers les fichiers Org-mode
|
||||
fichier_personnages = 'personnages.org'
|
||||
fichier_livre = 'livre.org'
|
||||
|
||||
# Expressions régulières pour extraire les noms des personnages et les titres des chapitres
|
||||
regex_personnage = r"\*\* (.*)"
|
||||
regex_chapitre = r'\*\* (.+)'
|
||||
|
||||
# Dictionnaire pour stocker les occurrences de personnages dans chaque chapitre
|
||||
occurrences_personnages = {}
|
||||
|
||||
# Ouvrir le fichier personnages.org et extraire les noms des personnages
|
||||
with open(fichier_personnages, 'r', encoding='utf-8') as fichier_personnages:
|
||||
personnages = [re.sub( "\*\* ","",ligne.strip()) for ligne in fichier_personnages if re.match(regex_personnage, ligne)]
|
||||
|
||||
print('personnages: ', personnages)
|
||||
|
||||
def contains_any_of_these_words(line: str, words: list[str]) -> bool:
|
||||
for word in words:
|
||||
if word in line:
|
||||
return True
|
||||
return False
|
||||
|
||||
# Ouvrir le fichier livre.org et le fichier CSV
|
||||
with open(fichier_livre, 'r', encoding='utf-8') as livre, open('occurrences_personnages.csv', 'w', newline='', encoding='utf-8') as fichier_csv:
|
||||
content = livre.read()
|
||||
csv_writer = csv.writer(fichier_csv)
|
||||
|
||||
# Écrire les en-têtes dans le fichier CSV
|
||||
csv_writer.writerow(['Chapitre'] + personnages)
|
||||
occurrences_chapitre = {personnage: 0 for personnage in personnages}
|
||||
chapitre = '(chapitre not found)'
|
||||
|
||||
# Parcourir chaque ligne du fichier livre.org
|
||||
for ligne in content.strip().split("\n"):
|
||||
# Rechercher le titre du chapitre
|
||||
match_chapitre = re.search(regex_chapitre, ligne)
|
||||
if match_chapitre:
|
||||
chapitre = match_chapitre.group(1)
|
||||
chapitre = re.sub( ":title:", "", chapitre)
|
||||
print(chapitre)
|
||||
# Initialiser le dictionnaire d'occurrences pour chaque chapitre
|
||||
occurrences_chapitre = {personnage: 0 for personnage in personnages}
|
||||
|
||||
# Parcourir chaque personnage et rechercher son nom dans la ligne
|
||||
for personnage in personnages:
|
||||
|
||||
if personnage in ligne:
|
||||
occurrences_chapitre[personnage] += 1
|
||||
print(chapitre,' - ',personnage,' : ', ligne)
|
||||
# Ajouter les occurrences du chapitre au dictionnaire global
|
||||
occurrences_personnages[chapitre] = occurrences_chapitre
|
||||
|
||||
# Écrire les occurrences des personnages dans le fichier CSV
|
||||
for chapitre, occurrences in occurrences_personnages.items():
|
||||
csv_writer.writerow([chapitre] + [occurrences[personnage] for personnage in personnages])
|
32
BD/omg_la_bd/scenario/gantt_parser.py
Normal file
32
BD/omg_la_bd/scenario/gantt_parser.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Lire le fichier CSV
|
||||
df = pd.read_csv('intrigues.csv')
|
||||
|
||||
# Créer un diagramme de Gantt
|
||||
fig, ax = plt.subplots(figsize=(10, 6))
|
||||
|
||||
# DéFinir les valeurs de Début et de Fin pour chaque tâche
|
||||
for i, row in df.iterrows():
|
||||
ax.plot([row['Début'], row['Fin']], [i, i], 'b-')
|
||||
ax.plot([row['Début'], row['Début']], [i-0.1, i+0.1], 'bo')
|
||||
ax.plot([row['Fin'], row['Fin']], [i-0.1, i+0.1], 'ro')
|
||||
|
||||
# DéFinir les étiquettes pour les tâches
|
||||
ax.set_yticks(range(len(df)))
|
||||
ax.set_yticklabels(df['Intrigue'])
|
||||
|
||||
# DéFinir les étiquettes pour les valeurs
|
||||
ax.set_xticks(range(int(df['Début'].min()), int(df['Fin'].max())+1))
|
||||
ax.set_xticklabels(ax.get_xticks())
|
||||
ax.plot([row['Début'], row['Fin']], [i, i], 'b-', linewidth=2)
|
||||
|
||||
# Ajouter un titre au diagramme
|
||||
ax.set_title('Intrigues')
|
||||
|
||||
# Afficher le diagramme
|
||||
#plt.show()
|
||||
#plt.figure(figsize=(16, 9))
|
||||
# Code pour tracer votre graphique
|
||||
plt.savefig("graphique_gantt_intrigues.png", dpi=72)
|
23
BD/omg_la_bd/scenario/generate_BD.sh
Executable file
23
BD/omg_la_bd/scenario/generate_BD.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# crée un nouveau fichier d'illustration à partir d'un modèle
|
||||
if [ -z "$1" ]; then
|
||||
echo "Erreur : Veuillez spécifier un nom pour le dossier de bande dessinée." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
nom_bd=$1
|
||||
dossier_bd="BD"
|
||||
|
||||
echo "création du dossier de bd: $nom_bd"
|
||||
mkdir -p $dossier_bd
|
||||
rm -rf "$dossier_bd/$nom_bd"
|
||||
cp -r _models/BD "$dossier_bd/$nom_bd"
|
||||
|
||||
# générer la partie scénario avec un modèle de livre
|
||||
./generate_book.sh "scenario_bd_generated_$nom_bd"
|
||||
mv scenario_bd_generated_$nom_bd/* "$dossier_bd/$nom_bd/scenario"
|
||||
rm -rf "scenario_bd_generated_$nom_bd"
|
||||
|
||||
ls -l $dossier_bd
|
||||
echo "dossier de bd $nom_bd créé avec un modèle de livre pour la partie scénario"
|
||||
exit 0
|
83
BD/omg_la_bd/scenario/generate_book.sh
Executable file
83
BD/omg_la_bd/scenario/generate_book.sh
Executable file
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
if [ -z "$1" ]; then
|
||||
echo "Erreur : Veuillez spécifier un argument." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
echo "Extension de fichiers générés au format org." >&2
|
||||
extension="org" # ou md
|
||||
fi
|
||||
function generate_uuid() {
|
||||
uuid=$(cat /proc/sys/kernel/random/uuid)
|
||||
echo "$uuid";
|
||||
return "$uuid";
|
||||
}
|
||||
|
||||
|
||||
livre_bidule=$1 # mettez le bon nom de votre livre
|
||||
echo "création du dossier de livre: $livre_bidule"
|
||||
|
||||
rm -rf "$livre_bidule"
|
||||
mkdir "$livre_bidule" -p
|
||||
cp *.py "$livre_bidule"
|
||||
cp *.sh "$livre_bidule"
|
||||
cp *.css "$livre_bidule"
|
||||
cd "$livre_bidule"
|
||||
mkdir assets inspirations
|
||||
touch "taches_$livre_bidule.$extension" \
|
||||
"livre.$extension" "intrigues.$extension" \
|
||||
"personnages.$extension" "notes_intention.$extension"
|
||||
|
||||
# On remplit les fiches avec un contenu de base:
|
||||
echo ":PROPERTIES:
|
||||
:ID: $(generate_uuid)
|
||||
:END:
|
||||
#+title: livre $livre_bidule
|
||||
#+AUTHOR: (votre nom)
|
||||
#+EMAIL: votre@email.com
|
||||
#+BEGIN_EXPORT epub
|
||||
:title \"Mon livre\"
|
||||
:author \"Votre nom\"
|
||||
:email \"votre@email.com\"
|
||||
:language \"fr\"
|
||||
:encoding \"UTF-8\"
|
||||
:subject \"Littérature\"
|
||||
:description \"Ceci est un livre écrit en Org-mode\"
|
||||
:keywords \"Org-mode, livre, électronique\"
|
||||
:cover \"image/cover.jpg\"
|
||||
#+END_EXPORT
|
||||
|
||||
|
||||
* Livre $livre_bidule :title:
|
||||
** Chapitre 1 :title:
|
||||
** Chapitre 2 :title:
|
||||
** Chapitre 3 :title:" > "livre.$extension"
|
||||
|
||||
echo ":PROPERTIES:
|
||||
:ID: $(generate_uuid)
|
||||
:END:
|
||||
#+title: notes d'intention de $livre_bidule
|
||||
|
||||
* Notes d'intention
|
||||
** Thématiques globales
|
||||
** Sources d'inspiration
|
||||
" > "notes_intention.$extension"
|
||||
|
||||
echo ":PROPERTIES:
|
||||
:ID: $(generate_uuid)
|
||||
:END:
|
||||
#+title: personnages de $livre_bidule
|
||||
|
||||
* Personnages
|
||||
** Principal
|
||||
- personnalité
|
||||
- objectifs
|
||||
** Secondaire
|
||||
|
||||
" > "personnages.$extension"
|
||||
|
||||
cd ..
|
||||
ls -l $livre_bidule
|
||||
echo "fichiers du livre $livre_bidule créé"
|
||||
exit 0
|
23
BD/omg_la_bd/scenario/generate_illustration.sh
Executable file
23
BD/omg_la_bd/scenario/generate_illustration.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# crée un nouveau fichier d'illustration à partir d'un modèle
|
||||
if [ -z "$1" ]; then
|
||||
echo "Erreur : Veuillez spécifier un nom pour le fichier d'illustration." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
extension="kra"
|
||||
# choix du modèle de base
|
||||
if [ "$2" ]; then
|
||||
extension=$2
|
||||
fi
|
||||
|
||||
nom_illustration=$1
|
||||
dossier_illustrations="illustrations"
|
||||
|
||||
echo "création du dossier d'illustrations: $nom_illustration"
|
||||
mkdir -p $dossier_illustrations
|
||||
cp _models/base_dessin.$extension "$dossier_illustrations/$nom_illustration"
|
||||
|
||||
ls -l $dossier_illustrations
|
||||
echo "fichier d'illustration $livre_bidule créé"
|
||||
exit 0
|
24
BD/omg_la_bd/scenario/install_dependances_ubuntu.sh
Normal file
24
BD/omg_la_bd/scenario/install_dependances_ubuntu.sh
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo " =============================================================================================== "
|
||||
echo " installation de dépendances pour faire ses propres ebook par tykayn de cipherbliss.com "
|
||||
echo " =============================================================================================== "
|
||||
|
||||
while true; do
|
||||
read -p " voulez-vous installer les dépendances nécessaire à la compilation d'ebook ? (o pour oui, n pour non) " yn
|
||||
case $yn in
|
||||
[Oo]* ) echo " nous allons installer Calibre et Pandoc avec apt; c'est parti!"; sudo apt install -y calibre pandoc; break;;
|
||||
[Nn]* ) echo "bon ok ._." ; break;;
|
||||
* ) echo "Veuillez répondre o pour oui, n pour non .";;
|
||||
esac
|
||||
done
|
||||
|
||||
while true; do
|
||||
read -p " voulez-vous cent balles et un mars ? (o pour oui, n pour non) " yn
|
||||
case $yn in
|
||||
[Oo]* ) echo "bah moi aussi tiens."; break;;
|
||||
[Nn]* ) echo "bon ok ._." ; exit;;
|
||||
* ) echo "Veuillez répondre o pour oui, n pour non .";;
|
||||
esac
|
||||
done
|
||||
|
0
BD/omg_la_bd/scenario/intrigues.org
Normal file
0
BD/omg_la_bd/scenario/intrigues.org
Normal file
23
BD/omg_la_bd/scenario/livre.org
Normal file
23
BD/omg_la_bd/scenario/livre.org
Normal file
|
@ -0,0 +1,23 @@
|
|||
:PROPERTIES:
|
||||
:ID: 29d5aac9-47ea-45e8-9adf-a25b557ae680
|
||||
:END:
|
||||
#+title: livre scenario_bd_generated_omg_la_bd
|
||||
#+AUTHOR: (votre nom)
|
||||
#+EMAIL: votre@email.com
|
||||
#+BEGIN_EXPORT epub
|
||||
:title "Mon livre"
|
||||
:author "Votre nom"
|
||||
:email "votre@email.com"
|
||||
:language "fr"
|
||||
:encoding "UTF-8"
|
||||
:subject "Littérature"
|
||||
:description "Ceci est un livre écrit en Org-mode"
|
||||
:keywords "Org-mode, livre, électronique"
|
||||
:cover "image/cover.jpg"
|
||||
#+END_EXPORT
|
||||
|
||||
|
||||
* Livre scenario_bd_generated_omg_la_bd :title:
|
||||
** Chapitre 1 :title:
|
||||
** Chapitre 2 :title:
|
||||
** Chapitre 3 :title:
|
33
BD/omg_la_bd/scenario/make_ebook.sh
Executable file
33
BD/omg_la_bd/scenario/make_ebook.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
EBOOK_NAME="camp_chatons_2021"
|
||||
|
||||
# Ce script sert à publier le mon_ebook.
|
||||
# La première version crée les documents mon_ebook.md et mon_ebook.html.
|
||||
# Le doc Markdown complet est volontairement supprimé. Je préfère que les modifications soient faites sur les différentes parties.
|
||||
# ce script doit être lancé dans le dossier contenant les chapitres.
|
||||
echo "=============== génération de mon ebook, c'est parti! =============== "
|
||||
# dépendances : sphinx-build pandoc
|
||||
hash ebook-convert 2>/dev/null || { echo >&2 "Ce générateur a besoin de la commande ebook-convert de Calibre pour fonctionner. Mais cette commande n'est pas installée. Fin de l'exécution."; exit 1; }
|
||||
#hash sphinx-build 2>/dev/null || { echo >&2 "Ce générateur a besoin de la commande sphinx-build pour fonctionner. Mais cette commande n'est pas installée. Fin de l'exécution."; exit 1; }
|
||||
hash pandoc 2>/dev/null || { echo >&2 "Ce générateur peut utiliser pandoc fourni avec Calibre, disponible dans les dépots apt. Mais cette commande n'est pas installée. Fin de l'exécution."; exit 1; }
|
||||
|
||||
# clean build
|
||||
rm -rf build/*
|
||||
cp -R source/img build/img
|
||||
|
||||
## Compilation HTML des différents chapitres
|
||||
bash table_des_matieres.sh
|
||||
|
||||
pandoc --standalone build/toutes_les_pages.md -o build/toutes_les_pages.html
|
||||
|
||||
|
||||
ebook-convert build/toutes_les_pages.html "build/$EBOOK_NAME.mobi"
|
||||
ebook-convert build/toutes_les_pages.html "build/$EBOOK_NAME.fb2"
|
||||
ebook-convert build/toutes_les_pages.html "build/$EBOOK_NAME.epub"
|
||||
|
||||
echo "===== générés: "
|
||||
ls -lArth build
|
||||
echo " "
|
||||
echo "===== ok pour la génération d'ebooks, vous pouvez les ouvrir dans Firefox ou votre lecteur d'ebook préféré"
|
||||
echo " "
|
38
BD/omg_la_bd/scenario/make_intrigues_to_csv.py
Normal file
38
BD/omg_la_bd/scenario/make_intrigues_to_csv.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import csv
|
||||
import re
|
||||
|
||||
# Remplacer par le chemin vers le fichier Org-mode
|
||||
fichier_org = 'intrigues.org'
|
||||
|
||||
# Expressions régulières pour extraire les dates et les intrigues
|
||||
regex_date = r'(\d+)-(\d+)'
|
||||
regex_intrigue = r'\* (.*)'
|
||||
|
||||
# Ouvrir le fichier Org-mode et le fichier CSV
|
||||
with open(fichier_org, 'r', encoding='utf-8') as fichier_org, open('intrigues.csv', 'w', newline='', encoding='utf-8') as fichier_csv:
|
||||
csv_writer = csv.writer(fichier_csv)
|
||||
|
||||
# Écrire les en-têtes dans le fichier CSV
|
||||
csv_writer.writerow(['Début', 'Fin', 'Intrigue'])
|
||||
line_counter=0
|
||||
# Parcourir chaque ligne du fichier Org-mode
|
||||
for ligne in fichier_org:
|
||||
# Initialiser les variables de date et d'intrigue à zéro
|
||||
debut = fin = intrigue = '0'
|
||||
|
||||
# Rechercher les dates de début et de fin
|
||||
match_date = re.search(regex_date, ligne)
|
||||
if match_date:
|
||||
debut = match_date.group(1)
|
||||
fin = match_date.group(2)
|
||||
else:
|
||||
debut = line_counter
|
||||
fin = line_counter+1
|
||||
# Rechercher l'intrigue
|
||||
match_intrigue = re.search(regex_intrigue, ligne)
|
||||
if match_intrigue:
|
||||
intrigue = re.sub(regex_date, "" , match_intrigue.group(1) )
|
||||
|
||||
# Écrire les informations dans le fichier CSV
|
||||
csv_writer.writerow([debut, fin, intrigue])
|
||||
line_counter+=1
|
9
BD/omg_la_bd/scenario/notes_intention.org
Normal file
9
BD/omg_la_bd/scenario/notes_intention.org
Normal file
|
@ -0,0 +1,9 @@
|
|||
:PROPERTIES:
|
||||
:ID: 1948e77b-ba48-41b3-8bab-04a9506a6308
|
||||
:END:
|
||||
#+title: notes d'intention de scenario_bd_generated_omg_la_bd
|
||||
|
||||
* Notes d'intention
|
||||
** Thématiques globales
|
||||
** Sources d'inspiration
|
||||
|
12
BD/omg_la_bd/scenario/personnages.org
Normal file
12
BD/omg_la_bd/scenario/personnages.org
Normal file
|
@ -0,0 +1,12 @@
|
|||
:PROPERTIES:
|
||||
:ID: 9912f8da-49eb-4f00-a2b6-d0ca033f924b
|
||||
:END:
|
||||
#+title: personnages de scenario_bd_generated_omg_la_bd
|
||||
|
||||
* Personnages
|
||||
** Principal
|
||||
- personnalité
|
||||
- objectifs
|
||||
** Secondaire
|
||||
|
||||
|
68
BD/omg_la_bd/scenario/render_ebook.py
Normal file
68
BD/omg_la_bd/scenario/render_ebook.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import subprocess
|
||||
import re
|
||||
|
||||
# Fichier Org d'origine
|
||||
fichier_org = "livre.org"
|
||||
style_css = "style.css"
|
||||
|
||||
# Copie du fichier Org
|
||||
fichier_org_copie = "livre_org_copie.org"
|
||||
|
||||
# Créer une copie du fichier Org
|
||||
with open(fichier_org, "r") as fichier:
|
||||
contenu_org = fichier.read()
|
||||
|
||||
with open(style_css, "r") as fichier:
|
||||
contenu_css = fichier.read()
|
||||
|
||||
# Compter le nombre de lignes du fichier original
|
||||
nb_lignes_origine = len(contenu_org.splitlines())
|
||||
|
||||
# Supprimer les titres qui ne contiennent pas le tag :title:
|
||||
contenu_org = re.sub(r"^\*+.*\n", lambda x: x.group() if ":title:" in x.group() else "", contenu_org, flags=re.MULTILINE)
|
||||
|
||||
|
||||
# Effacer toutes les occurences de ":title:"
|
||||
contenu_org = re.sub(r":title:", "", contenu_org)
|
||||
|
||||
# Compter le nombre de lignes du fichier modifié
|
||||
nb_lignes_modifie = len(contenu_org.splitlines())
|
||||
|
||||
# Afficher le nombre de lignes supprimées
|
||||
nb_lignes_supprimees = nb_lignes_origine - nb_lignes_modifie
|
||||
print(f"Nombre de lignes supprimées : {nb_lignes_supprimees}")
|
||||
|
||||
# Écrire la copie du fichier Org
|
||||
with open(fichier_org_copie, "w") as fichier:
|
||||
fichier.write(contenu_org)
|
||||
|
||||
print('Convertir la copie du fichier Org en HTML')
|
||||
|
||||
# Convertir la copie du fichier Org en HTML
|
||||
process = subprocess.run(["pandoc", "livre_org_copie.org", "-o", "livre.html"], capture_output=True, text=True)
|
||||
|
||||
# Afficher les messages de console du subprocess
|
||||
print(process.stdout)
|
||||
print(process.stderr)
|
||||
|
||||
|
||||
# ouvrir le html et insérer le style css TODO
|
||||
with open("livre.html", "r") as fichier:
|
||||
contenu_html = fichier.read()
|
||||
contenu_html = re.sub("</head>", "<style type='text/css' >"+contenu_css+"</style></head>", contenu_org)
|
||||
with open(fichier_org_copie, "w") as fichier:
|
||||
fichier.write(contenu_org)
|
||||
|
||||
print('Convertir la copie du fichier Org en pdf')
|
||||
process = subprocess.run(["pandoc", "livre.org", "-o", "livre.pdf"], capture_output=True, text=True)
|
||||
|
||||
# Afficher les messages de console du subprocess
|
||||
print(process.stdout)
|
||||
print(process.stderr)
|
||||
|
||||
print('Convertir la copie du fichier Org en ebook')
|
||||
process = subprocess.run(["pandoc", "livre.org", "-o", "livre.epub"], capture_output=True, text=True)
|
||||
|
||||
# Afficher les messages de console du subprocess
|
||||
print(process.stdout)
|
||||
print(process.stderr)
|
56
BD/omg_la_bd/scenario/stats_chapitres.py
Normal file
56
BD/omg_la_bd/scenario/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.")
|
23
BD/omg_la_bd/scenario/structure_generator.py
Normal file
23
BD/omg_la_bd/scenario/structure_generator.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# python script.py --number_chapters 7 --number_parts 2 --objective_words 600 --objective_chapter 1800
|
||||
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--objective_words', type=int, default=500)
|
||||
parser.add_argument('--objective_chapter', type=int, default=1500)
|
||||
parser.add_argument('--number_chapters', type=int, default=5)
|
||||
parser.add_argument('--number_parts', type=int, default=3)
|
||||
args = parser.parse_args()
|
||||
book_content = ''
|
||||
|
||||
print(args)
|
||||
|
||||
for i in range(args.number_chapters):
|
||||
book_content += f"\n\n### Chapitre {i+1} :title:target_{args.objective_words}:"
|
||||
for j in range(args.number_parts):
|
||||
book_content += f"\n\n### Chapitre {i+1} - Partie {j+1} :title:target_{args.objective_words}:"
|
||||
|
||||
print("--------------")
|
||||
print(book_content)
|
||||
print("--------------")
|
||||
print("vous pouvez copier cette cascade de parties de livre dans livre.org")
|
169
BD/omg_la_bd/scenario/style.css
Normal file
169
BD/omg_la_bd/scenario/style.css
Normal file
|
@ -0,0 +1,169 @@
|
|||
body {
|
||||
max-width: 80vw;
|
||||
margin: 1rem auto;
|
||||
}
|
||||
|
||||
#table-of-contents {
|
||||
font-size: 1rem;
|
||||
border-left: solid 3px;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
#table-of-contents h2 {
|
||||
font-size: 1rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.section-number-2 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.title sub {
|
||||
font-size: 1em;
|
||||
margin-left: 0.5ch;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
font-weight: 700;
|
||||
color: crimson;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #111;
|
||||
font-family: 'Open Sans Condensed', sans-serif;
|
||||
font-size: 64px;
|
||||
font-weight: 700;
|
||||
line-height: 64px;
|
||||
margin: 0 0 0;
|
||||
padding: 20px 30px;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #111;
|
||||
font-family: 'Open Sans Condensed', sans-serif;
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
line-height: 48px;
|
||||
margin: 0 0 24px;
|
||||
padding: 0 30px;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #111;
|
||||
font-family: 'Calibri', 'Open Sans', sans-serif;
|
||||
font-size: 1rem;
|
||||
line-height: 1.5rem;
|
||||
margin: 0 0 2rem;
|
||||
/*columns:3;*/
|
||||
}
|
||||
|
||||
a {
|
||||
color: #990000;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline
|
||||
}
|
||||
|
||||
.date {
|
||||
color: #111;
|
||||
display: block;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 16px;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
z-index: 1;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.date:before {
|
||||
border-top: 1px solid #111;
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0rem;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.author {
|
||||
color: #111;
|
||||
display: block;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 16px;
|
||||
padding-bottom: 38px;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
z-index: 1;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.author:before {
|
||||
border-top: 1px solid #111;
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0rem;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.date span,
|
||||
.author span {
|
||||
background: #fdfdfd;
|
||||
padding: 0 10px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.line {
|
||||
border-top: 1px solid #111;
|
||||
display: block;
|
||||
margin-top: 60px;
|
||||
padding-top: 50px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.read-more {
|
||||
-moz-border-radius: 50%;
|
||||
-moz-transition: all 0.2s ease-in-out;
|
||||
-webkit-border-radius: 50%;
|
||||
-webkit-transition: all 0.2s ease-in-out;
|
||||
background: #111;
|
||||
border-radius: 50%;
|
||||
border: 10px solid #fdfdfd;
|
||||
color: #fff;
|
||||
display: block;
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
font-size: 14px;
|
||||
height: 80px;
|
||||
line-height: 80px;
|
||||
margin: -40px 0 0 -40px;
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
left: 50%;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.read-more:hover {
|
||||
background: #990000;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.org-src-container {
|
||||
background: #dedede;
|
||||
padding: 0.5rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
pre.example {
|
||||
background: #ccc;
|
||||
padding: 0.5rem;
|
||||
margin: 1rem;
|
||||
}
|
109
BD/omg_la_bd/scenario/table_des_matieres.sh
Normal file
109
BD/omg_la_bd/scenario/table_des_matieres.sh
Normal file
|
@ -0,0 +1,109 @@
|
|||
#!/bin/bash
|
||||
|
||||
# motivation to rewrite a simple alternative to doctoc: How Much Do You Trust That Package? Understanding The Software Supply Chain https://www.youtube.com/watch?v=fnELtqE6mMM
|
||||
# src https://gist.github.com/meleu/57867f4a01ede1bd730f14b2f018ae89
|
||||
|
||||
############
|
||||
# Generates a Table of Contents getting a markdown file as input.
|
||||
#
|
||||
# Inspiration for this script:
|
||||
# https://medium.com/@acrodriguez/one-liner-to-generate-a-markdown-toc-f5292112fd14
|
||||
#
|
||||
# The list of invalid chars is probably incomplete, but is good enough for my
|
||||
# current needs.
|
||||
# Got the list from:
|
||||
# https://github.com/thlorenz/anchor-markdown-header/blob/56f77a232ab1915106ad1746b99333bf83ee32a2/anchor-markdown-header.js#L25
|
||||
#
|
||||
|
||||
PAGE_TOC="sources/99_03_table_des_matieres.md"
|
||||
|
||||
INVALID_CHARS="'[]/?!:\`.,()*\";{}+=<>~$|#@&–—"
|
||||
|
||||
file_md_to_inspect="build/toutes_les_pages.md"
|
||||
|
||||
echo "build a concatenation of all pages..."
|
||||
rm -rf build/toutes_les_pages.md
|
||||
|
||||
|
||||
for i in source/*.md ; do
|
||||
# if [ "sources/99_03_table_des_matières.md" != $i ] ; then
|
||||
echo "adding $i"
|
||||
cat $i >> build/toutes_les_pages.md
|
||||
echo "lignes en tout:"
|
||||
cat build/toutes_les_pages.md | wc -l
|
||||
# else
|
||||
# echo "not adding $i"
|
||||
# fi
|
||||
done
|
||||
|
||||
cat build/toutes_les_pages.md |wc -l
|
||||
|
||||
echo "OK"
|
||||
|
||||
|
||||
echo "markdown file to inspect: $file_md_to_inspect"
|
||||
|
||||
|
||||
check() {
|
||||
|
||||
# src https://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script
|
||||
if [ -z build/toutes_les_pages.md ]; then
|
||||
echo "Error. No argument found. Put as argument a file.md"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ ! -f build/toutes_les_pages.md ]] && echo "Error. File not found" && exit
|
||||
|
||||
}
|
||||
|
||||
toc() {
|
||||
|
||||
local line
|
||||
local level
|
||||
local title
|
||||
local anchor
|
||||
local output
|
||||
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
level="$(echo "$line" | sed -E 's/^#(#+).*/\1/; s/#/ /g; s/^ //')"
|
||||
title="$(echo "$line" | sed -E 's/^#+ //')"
|
||||
anchor="$(echo "$title" | tr '[:upper:] ' '[:lower:]-' | tr -d "$INVALID_CHARS")"
|
||||
output=$output"$level- [$title](#$anchor)\n"
|
||||
done <<< "$(grep -E '^#{2,10} ' $1 | tr -d '\r')"
|
||||
|
||||
echo "$output"
|
||||
|
||||
}
|
||||
|
||||
insert() {
|
||||
|
||||
local toc_text="$2"
|
||||
local appname='doctoc.sh'
|
||||
# inspired in doctoc lines
|
||||
local start_toc="<!-- START $appname generated TOC please keep comment here to allow auto update -->"
|
||||
local info_toc="<!-- DO NOT EDIT THIS SECTION, INSTEAD RE-RUN $appname TO UPDATE -->"
|
||||
local end_toc="<!-- END $appname generated TOC please keep comment here to allow auto update -->"
|
||||
|
||||
toc_block="$start_toc\n$info_toc\n**Table of Contents**\n\n$toc_text\n$end_toc"
|
||||
|
||||
# search multiline toc block -> https://stackoverflow.com/questions/2686147/how-to-find-patterns-across-multiple-lines-using-grep/2686705
|
||||
if grep -Pzl "(?s)$start_toc.*\n.*$end_toc" build/toutes_les_pages.md &>/dev/null; then
|
||||
echo -e "\n Updated content of $appname block for build/toutes_les_pages.md succesfully\n"
|
||||
# src https://askubuntu.com/questions/533221/how-do-i-replace-multiple-lines-with-single-word-in-fileinplace-replace
|
||||
sed -i ":a;N;\$!ba;s/$start_toc.*$end_toc/$toc_block/g" build/toutes_les_pages.md
|
||||
else
|
||||
echo -e "\n Created $appname block for build/toutes_les_pages.md succesfully\n"
|
||||
sed -i 1i"$toc_block" build/toutes_les_pages.md
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
check build/toutes_les_pages.md
|
||||
toc_text=$(toc "build/toutes_les_pages.md")
|
||||
insert "build/toutes_les_pages.md" "$toc_text"
|
||||
|
||||
}
|
||||
|
||||
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
|
7
BD/omg_la_bd/scenario/up_infos.sh
Executable file
7
BD/omg_la_bd/scenario/up_infos.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "mise à jour des infos"
|
||||
python3 find_characters_in_book.py
|
||||
python3 stats_chapitres.py
|
||||
python3 make_intrigues_to_csv.py
|
||||
python3 gantt_parser.py
|
17
BD/omg_la_bd/scenario/update_book.sh
Executable file
17
BD/omg_la_bd/scenario/update_book.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
if [ -z "$1" ]; then
|
||||
echo "Erreur : Veuillez spécifier un nom de dossier de livre à mettre à jour." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "mise à jour du dossier $1 sans modifier les contenus Org"
|
||||
|
||||
dossier=$1
|
||||
|
||||
cp *.py "$dossier/"
|
||||
cp *.sh "$dossier/"
|
||||
cp *.css "$dossier/"
|
||||
cp README.md "$dossier/"
|
||||
cp LICENSE "$dossier/"
|
||||
cp Makefile "$dossier/"
|
||||
|
||||
echo "dossier $dossier mis à jour"
|
0
BD/omg_la_bd/scenario/variables.sh
Normal file
0
BD/omg_la_bd/scenario/variables.sh
Normal file
Loading…
Add table
Add a link
Reference in a new issue