feat(Python): version Python du code de fusion des documents
This commit is contained in:
		
							
								
								
									
										4
									
								
								python/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								python/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
bin
 | 
			
		||||
include
 | 
			
		||||
lib
 | 
			
		||||
lib64
 | 
			
		||||
							
								
								
									
										38
									
								
								python/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								python/main.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
import os
 | 
			
		||||
from tkinter import Tk, Button, filedialog
 | 
			
		||||
from docx import Document
 | 
			
		||||
 | 
			
		||||
def fusionner_docx(dossier):
 | 
			
		||||
    doc_fusionne = Document()
 | 
			
		||||
 | 
			
		||||
    for fichier in os.listdir(dossier):
 | 
			
		||||
        if fichier.endswith(".docx"):
 | 
			
		||||
            chemin_fichier = os.path.join(dossier, fichier)
 | 
			
		||||
            doc = Document(chemin_fichier)
 | 
			
		||||
 | 
			
		||||
            for para in doc.paragraphs:
 | 
			
		||||
                nouveau_para = doc_fusionne.add_paragraph()
 | 
			
		||||
                nouveau_para.alignment = para.alignment
 | 
			
		||||
                for run in para.runs:
 | 
			
		||||
                    nouveau_run = nouveau_para.add_run(run.text)
 | 
			
		||||
                    nouveau_run.bold = run.bold
 | 
			
		||||
                    nouveau_run.italic = run.italic
 | 
			
		||||
                    nouveau_run.underline = run.underline
 | 
			
		||||
 | 
			
		||||
    doc_fusionne.save("fusion.docx")
 | 
			
		||||
    print("Documents fusionnés dans fusion.docx")
 | 
			
		||||
 | 
			
		||||
def selectionner_dossier():
 | 
			
		||||
    dossier = filedialog.askdirectory()
 | 
			
		||||
    if dossier:
 | 
			
		||||
        fusionner_docx(dossier)
 | 
			
		||||
 | 
			
		||||
# Création de la fenêtre Tkinter
 | 
			
		||||
root = Tk()
 | 
			
		||||
root.title("Sélectionner un dossier")
 | 
			
		||||
 | 
			
		||||
btn = Button(root, text="Sélectionner un dossier", command=selectionner_dossier)
 | 
			
		||||
btn.pack(pady=20)
 | 
			
		||||
 | 
			
		||||
root.mainloop()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								python/pyvenv.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								python/pyvenv.cfg
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
home = /usr/bin
 | 
			
		||||
include-system-site-packages = false
 | 
			
		||||
version = 3.12.4
 | 
			
		||||
executable = /usr/bin/python3.12
 | 
			
		||||
command = /usr/bin/python -m venv /home/od/test/golang_examples/exo3/python
 | 
			
		||||
							
								
								
									
										3
									
								
								python/requirements
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								python/requirements
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
lxml==5.2.2
 | 
			
		||||
python-docx==1.1.2
 | 
			
		||||
typing_extensions==4.12.2
 | 
			
		||||
		Reference in New Issue
	
	Block a user