diff options
| author | Debulois Quentin <quentin.debulois@gmail.com> | 2022-04-12 15:41:36 +0200 |
|---|---|---|
| committer | Debulois Quentin <quentin.debulois@gmail.com> | 2022-04-12 15:41:36 +0200 |
| commit | fee40ff1c9d7aa2a75235d5a54e411ca2665b100 (patch) | |
| tree | ad4c473140807493312db18fe10da873b7714af5 | |
| parent | f3e632cb20be41d58f3aca4eaacfdb150a6186d4 (diff) | |
Ajout des délaisdevelop
| -rwxr-xr-x | main.py | 60 |
1 files changed, 49 insertions, 11 deletions
@@ -9,12 +9,15 @@ Cahier des charges: import os import sys +import re +from datetime import date import fitz #pymupdf if len(sys.argv) != 2: print("Il faut indiquer le dossier ou sont les factures.") exit(1) +reg_date = "[0-9]{2}/[0-9]{2}/[0-9]{4}" folder = sys.argv[1] files = os.listdir(folder) texte_date_emission = "Date d'émission :" @@ -32,33 +35,62 @@ for i in files: texte += page.get_text() text = texte.split("\n") - try: - date_emission = text[text.index(texte_date_emission) + 1].split("/")[1:] - except: - print("Erreur date: ", i) - continue - - key = date_emission[1] + "-" + date_emission[0] + list_date = [] + for j in text: + if re.search(reg_date, j): + list_date.append(j) + + date_f = list_date[0].split("/") # facture + date_p = [] + list_date_p = list_date[1].split(" ") # paiement + for j in date_p: + if re.search(reg_date, j): + date_p = j.split("/") + + key = date_f[2] + "-" + date_f[1] if key not in dict_final: dict_final[key] = {} dict_final[key]["pc"] = 0 dict_final[key]["piece"] = 0 dict_final[key]["prix_pc"] = 0 dict_final[key]["prix_piece"] = 0 - dict_final[key]["type_reglement"] = {} dict_final[key]["nom_factures"] = [] + dict_final[key]["type_reglement"] = {} + dict_final[key]["temps_fabrication"] = [] is_pc = False for j in text: if texte_montage in j: - dict_final[key]["pc"] += 1 is_pc = True + delta = date(int(date_f[2]), int(date_f[1]), int(date_f[0])) \ + - date(int(date_p[2][:4]), int(date_p[1]), int(date_p[0])) + dict_final[key]["temps_fabrication"].append(delta.total_seconds() / 86400) + if is_pc: - dict_final[key]["nom_factures"].append(i + " - PC") + dict_final[key]["pc"] += 1 + dict_final[key]["nom_factures"].append( + i + + " PC Paiement: " + + "/".join(date_p) + + " Facture: " + + "/".join(date_f) + + " Delta: " + + str(delta.total_seconds() / 86400) + + " jours." + ) else: dict_final[key]["piece"] += 1 - dict_final[key]["nom_factures"].append(i + " - PIECE") + dict_final[key]["nom_factures"].append( + i + + " PIECE Paiement: " + + "/".join(date_p) + + " Facture: " + + "/".join(date_f) + + " Delta: " + + str(delta.total_seconds() / 86400) + + " jours." + ) if texte_prix_ttc in text: if is_pc: @@ -77,6 +109,7 @@ for i in files: for i in dict_final: if not os.path.isdir(os.path.join(folder, i)): os.mkdir(os.path.join(folder, i)) + if dict_final[i]["pc"] == 0: dict_final[i]["pc"] = 1 if dict_final[i]["piece"] == 0: @@ -91,12 +124,15 @@ for i in dict_final: + "\nNb Pieces: " + str(dict_final[i]["piece"])\ + "\nPrix Pieces: " + str(round(dict_final[i]["prix_piece"], 2)) + "€"\ + "\nPrix moyen: " + str(round(dict_final[i]["prix_piece"] / dict_final[i]["piece"], 2)) + "€"\ + + "\n\n### DELAI MOYEN ###"\ + + "\nDelai moyen de " + str(round(sum(dict_final[i]["temps_fabrication"]) / len(dict_final[i]["temps_fabrication"]), 2)) + " jours."\ + "\n\n### TYPE DE REGLEMENT ###\n" for j in dict_final[i]["type_reglement"]: texte_final = texte_final + j + ": " + str(dict_final[i]["type_reglement"][j]) + "\n" texte_final = texte_final + "\n### NOM DES FACTURES ###\n" + for j in dict_final[i]["nom_factures"]: texte_final = texte_final + j + "\n" os.rename(j.split(" ")[0], os.path.join(i, j.split(" ")[0])) @@ -104,6 +140,7 @@ for i in dict_final: with open(i + "_pcmesure.txt", "w") as f: f.write(texte_final) + """ # Pourrait être utile ? # Pièces du PC @@ -122,3 +159,4 @@ for i in chunks: print(len(final[:-2])) print(final) """ + |
