浏览代码

entre autres, passage en yml

Thierry Dumont 1 月之前
父节点
当前提交
86e0c3bf32
共有 5 个文件被更改,包括 29 次插入19 次删除
  1. 1 1
      All/tout.py
  2. 2 2
      README.md
  3. 10 0
      data.yml
  4. 0 6
      data_titre.proto
  5. 16 10
      extr.py

+ 1 - 1
All/tout.py

@@ -18,7 +18,7 @@ def addpath(x,ajout):
         return x
 #
 templat= "../tpl.tex"
-# Récupérer le liste des txtes à introduire
+# Récupérer le liste des textes à introduire
 with open("all_texts") as f:
     lf= f.readlines()
 #on récupère le template

+ 2 - 2
README.md

@@ -2,7 +2,7 @@
 
 #### Dans ce répertoire
 
-  - configurer data_titre
+  - configurer data.yml  (prototype au dessus)
   
   - python ../extr1.py
 
@@ -11,6 +11,6 @@
 
   -configurer all_texts
   
-   -python tout.py   ( fabrique le fichier final.tex)
+   -python tout.py   (fabrique le fichier final.tex)
    
   -compiler final.tex avec lualatex

+ 10 - 0
data.yml

@@ -0,0 +1,10 @@
+fichier: dumont.odt
+date: Mardi 32 Mai 2021
+auteur: Thierry Dumont
+# statut est le seul champ facultatif
+# s'il est absent, on peut omettre type, qui sera toujours Communication
+statut: membre titulaire
+type: Communication
+#
+titre: Algorithmes
+

+ 0 - 6
data_titre.proto

@@ -1,6 +0,0 @@
-fichier à traiter docx ou odt
-date: Mardi 25 Mai 2021
-communication/conférence: Communication
-Nom Prénom:Pierre Crépel
-tituleire/associé ou ligne de blancs:membre titulaire
-titre: La statistique et l'Académie de Lyon dans la première moitié du XIX\ieme{} siècle

+ 16 - 10
extr.py

@@ -1,6 +1,7 @@
 #!./venv/bin/python
-import sys,pypandoc,os,re,subprocess
+import sys,pypandoc,os,re,subprocess,yaml
 #
+data_yml_manadatory_keys=['fichier', 'date', 'type', 'auteur', 'titre']
 def star_sec(l):
     it=iter(L)
     ret=[]
@@ -27,17 +28,22 @@ def star_sec(l):
 #
 
 #-----------------------------------------------------------------------
-with open("data_titre") as f:
-    lt=f.readlines()
-if (llt:=len(lt))!=6:
-    m=f"\nle fichier data-titre a {llt} lignes (il en faut 6)"
-    raise Exception(m)
-fich=lt[0].strip()
-le_titre="\\titre{"+"}{".join([x.replace("\n","") for x in lt[1:]])+"}"+"\n"
+# Construire le titre à partir du fichier yml.
+#-----------------------------------------------------------------------
+with open("data.yml") as f:
+    lt=yaml.safe_load(f)
+
+if not "statut" in  lt.keys():
+    lt["statut"]=" "
+    lt["type"]="Conférence"
+fich=lt["fichier"].strip()
+titre_elements="}{".join([lt[x].replace("\n","") for x in lt.keys()
+                          if x!="fichier"])
+le_titre="\\titre{"+titre_elements+"}"+"\n"
 print(le_titre)
-#
+#--------------------------------------------------------------------
 template="../tpl.tex"
-#
+#---------------------------------------------------------------------
 exten=fich.split(".")[-1]
 
 if exten=="docx" or exten=="odt":