[fix] yaml conversion should work

This commit is contained in:
alban 2023-10-19 20:26:14 +02:00
parent 6b5722a60b
commit 097d4ec451
2 changed files with 104964 additions and 101251 deletions

View File

@ -3,7 +3,7 @@ import re
import yaml import yaml
# Première partie : Les relations individuelles de travail # Première partie : Les relations individuelles de travail
re_partie = re.compile("^[^ ]+ partie") re_partie = re.compile("^[^ ]+ partie :")
# Livre Ier : Dispositions préliminaires # Livre Ier : Dispositions préliminaires
re_livre = re.compile("^Livre") re_livre = re.compile("^Livre")
@ -14,6 +14,12 @@ re_titre = re.compile("^Titre")
# Chapitre unique. # Chapitre unique.
re_chapitre = re.compile("^Chapitre") re_chapitre = re.compile("^Chapitre")
# Chapitre unique.
re_chapitre = re.compile("^Chapitre")
# Section 3 : Organismes consultatifs
re_section = re.compile("^Section ")
# Article L1111-1 # Article L1111-1
re_article = re.compile("^Article") re_article = re.compile("^Article")
@ -24,31 +30,42 @@ class Doc():
livre: str = "" livre: str = ""
titre: str = "" titre: str = ""
chapitre: str = "" chapitre: str = ""
section: str = ""
article: str = "" article: str = ""
text: str = "" text: str = ""
def set_partie(self, arg: str): def set_partie(self, arg: str):
self.partie = arg self.partie = arg
self.livre = self.titre = self.chapitre = self.text = "" self.livre = self.titre = self.chapitre = self.section = self.article = self.text = ""
def set_livre(self, arg: str): def set_livre(self, arg: str):
self.livre = arg self.livre = arg
self.titre = self.chapitre = self.text = "" self.titre = self.chapitre = self.section = self.article = self.text = ""
def set_titre(self, arg: str): def set_titre(self, arg: str):
self.titre = arg self.titre = arg
self.chapitre = self.text = "" self.chapitre = self.section = self.article = self.text = ""
def set_chapitre(self, arg: str): def set_chapitre(self, arg: str):
self.chapitre = arg self.chapitre = arg
self.text = "" self.section = self.article = self.text = ""
def set_section(self, arg: str):
self.section = arg
self.article = self.text = ""
def set_article(self, arg: str): def set_article(self, arg: str):
self.article = arg self.article = arg
self.text = "" self.text = ""
def set_text(self, arg: str): def set_text(self, arg: str):
# Certains livre n'ont pas de chapitre manifest
if not self.chapitre:
self.chapitre = "Chapitre unique"
if not self.section:
self.section = "Section unique"
self.text += arg + " " self.text += arg + " "
if not self.partie in self.content: if not self.partie in self.content:
self.content[self.partie] = {} self.content[self.partie] = {}
if not self.livre in self.content[self.partie]: if not self.livre in self.content[self.partie]:
@ -57,9 +74,11 @@ class Doc():
self.content[self.partie][self.livre][self.titre] = {} self.content[self.partie][self.livre][self.titre] = {}
if not self.chapitre in self.content[self.partie][self.livre][self.titre]: if not self.chapitre in self.content[self.partie][self.livre][self.titre]:
self.content[self.partie][self.livre][self.titre][self.chapitre] = {} self.content[self.partie][self.livre][self.titre][self.chapitre] = {}
if not self.article in self.content[self.partie][self.livre][self.titre][self.chapitre]: if not self.section in self.content[self.partie][self.livre][self.titre][self.chapitre]:
self.content[self.partie][self.livre][self.titre][self.chapitre][self.article] = "" self.content[self.partie][self.livre][self.titre][self.chapitre][self.section] = {}
self.content[self.partie][self.livre][self.titre][self.chapitre][self.article] = self.text if not self.article in self.content[self.partie][self.livre][self.titre][self.chapitre][self.section]:
self.content[self.partie][self.livre][self.titre][self.chapitre][self.section][self.article] = ""
self.content[self.partie][self.livre][self.titre][self.chapitre][self.section][self.article] = self.text
Document = Doc() Document = Doc()
@ -74,6 +93,8 @@ def parse_line(line: str, doc: Doc) -> int:
doc.set_titre(line) doc.set_titre(line)
elif re_chapitre.match(line): elif re_chapitre.match(line):
doc.set_chapitre(line) doc.set_chapitre(line)
elif re_section.match(line):
doc.set_section(line)
elif re_article.match(line): elif re_article.match(line):
doc.set_article(line) doc.set_article(line)
else: else:
@ -95,4 +116,4 @@ for line in lines:
with open("./sources/code-travail.yaml", "w") as fh: with open("./sources/code-travail.yaml", "w") as fh:
yaml.safe_dump(doc.content, fh) yaml.safe_dump(doc.content, fh)
# print(doc) # print(doc)

File diff suppressed because it is too large Load Diff