feature : Error repport xlsx with files per folder
This commit is contained in:
parent
28b879720f
commit
7381ae0aa4
@ -8,6 +8,7 @@ import shutil
|
||||
import unicodedata
|
||||
from datetime import datetime
|
||||
import openpyxl as xls
|
||||
from openpyxl.styles import PatternFill
|
||||
|
||||
|
||||
# Les noms de tous les dossier a créer
|
||||
@ -129,6 +130,7 @@ def sort_files(prefixe, suffixe, sort_path):
|
||||
|
||||
#compte le nombre de fois mot clef apparait
|
||||
keyword_count = {key: 0 for key in KEYWORDS}
|
||||
folders_file_count = [0] * len(FOLDERNAMES)
|
||||
|
||||
for file in files:
|
||||
no_keyword = True
|
||||
@ -152,6 +154,7 @@ def sort_files(prefixe, suffixe, sort_path):
|
||||
os.path.dirname(file),
|
||||
prefixe + "_" + filename + "_" + suffixe + ".pdf",)
|
||||
|
||||
folders_file_count[int(folder[0])] +=1
|
||||
os.rename(file, renamed)
|
||||
shutil.move(renamed, new_path)
|
||||
no_keyword = False
|
||||
@ -180,14 +183,18 @@ def sort_files(prefixe, suffixe, sort_path):
|
||||
)
|
||||
os.rename(file, renamed)
|
||||
shutil.move(renamed, sort_path + "/" + FOLDERNAMES[ANNEXE_FOLDER_ID])
|
||||
folders_file_count[ANNEXE_FOLDER_ID] += 1
|
||||
|
||||
return keyword_count
|
||||
return keyword_count, folders_file_count
|
||||
# return True
|
||||
|
||||
def error_report(data):
|
||||
def error_report(file_data,folder_data):
|
||||
"""
|
||||
Crée le rapport d'utilisation du script
|
||||
"""
|
||||
#Couleur rouge
|
||||
error_color =PatternFill(patternType='solid',fgColor='00FF0000')
|
||||
|
||||
report = xls.Workbook()
|
||||
report_worsheet = report.active
|
||||
report_worsheet.title = "Compte rendu"
|
||||
@ -200,15 +207,25 @@ def error_report(data):
|
||||
report_worsheet.column_dimensions['B'].width *= 3
|
||||
report_worsheet.column_dimensions['F'].width *= 3
|
||||
report_worsheet.column_dimensions['G'].width *= 3
|
||||
report_worsheet.column_dimensions['H'].width *= 3
|
||||
|
||||
currrent_cell = 2
|
||||
for key in data:
|
||||
for key in file_data:
|
||||
report_worsheet['A'+ str(currrent_cell)] = key
|
||||
report_worsheet['B'+ str(currrent_cell)] = data.get(key)
|
||||
report_worsheet['B'+ str(currrent_cell)] = file_data.get(key)
|
||||
currrent_cell+=1
|
||||
|
||||
report_worsheet['A'+str(3 + len(data.keys()))] = "Total fichiers"
|
||||
report_worsheet['B'+str(3 + len(data.keys()))] = '=SUM(B2:B' + str(1 + len(data.keys())) + ')'
|
||||
currrent_cell = 2
|
||||
for i, content in enumerate(folder_data):
|
||||
report_worsheet['F'+ str(currrent_cell)] = FOLDERNAMES[i]
|
||||
report_worsheet['G'+ str(currrent_cell)] = content
|
||||
if content == 0:
|
||||
report_worsheet['H'+ str(currrent_cell)] = "/!\\ aucun fichier dans le dossier /!\\"
|
||||
report_worsheet['H'+ str(currrent_cell)].fill = error_color
|
||||
currrent_cell+=1
|
||||
|
||||
report_worsheet['A'+str(3 + len(file_data.keys()))] = "Total fichiers"
|
||||
report_worsheet['B'+str(3 + len(file_data.keys()))] = '=SUM(B2:B' + str(1 + len(file_data.keys())) + ')'
|
||||
report.save("Rapport.xlsx")
|
||||
|
||||
def sortout():
|
||||
@ -245,6 +262,6 @@ def sortout():
|
||||
|
||||
main_path = create_folders(is_plu, prefixe, suffixe)
|
||||
|
||||
donees_fichiers = sort_files(prefixe, suffixe, main_path)
|
||||
donees_fichiers, donnees_dossiers = sort_files(prefixe, suffixe, main_path)
|
||||
|
||||
error_report(donees_fichiers)
|
||||
error_report(donees_fichiers,donnees_dossiers)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user