From fe43a7e23286d0f635bf093721ff5426a9e4a2de Mon Sep 17 00:00:00 2001 From: jfontaine35 <76435797+jfontaine35@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:44:15 +0200 Subject: [PATCH] Update Accrochage.py --- Accrochage.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Accrochage.py b/Accrochage.py index 323f4f1..ea789f1 100644 --- a/Accrochage.py +++ b/Accrochage.py @@ -1,9 +1,3 @@ -#Traitement des fichiers csv fournit avant de lancer ce script : -# - Remplacement des ; par des , sous gedit -# - Ouvrir avec libre office et supprimer toute les , parasites -# - Mettre les date de la colonne K au format "aaaa-mm-jj" - - import xml.etree.ElementTree as ET import csv import random @@ -47,7 +41,7 @@ def indent(elem, level=0): def create_xml_from_csv(csv_filepath, xml_filepath): logging.info("Ouverture du CSV...") # Ouvrir le fichier CSV pour la lecture - with open(csv_filepath, newline='', encoding='UTF-8') as csvfile: + with open(csv_filepath, newline='', encoding='utf-8') as csvfile: reader = csv.reader(csvfile) Allrows = list(reader) @@ -68,19 +62,20 @@ def create_xml_from_csv(csv_filepath, xml_filepath): now = datetime.datetime.now(tz_paris) value = now.strftime("%Y-%m-%dT%H:%M:%S+01:00") - ET.SubElement(root, "cpf:idFlux").text = str(random.randint(1000000000, 99999999999)) + ET.SubElement(root, "cpf:idFlux").text = headers[0] + #str(random.randint(1000000000, 99999999999)) ET.SubElement(root, "cpf:horodatage").text = value # Création et ajout de l'élément emetteur emetteur = ET.SubElement(root, "cpf:emetteur") - logging.info("Emmetteur du fichier ...") + logging.info("Emmetteur du fchier ...") # Création de la structure des certificateurs - idClient = str(random.randint(10000000, 99999999)) if Allrows[5][2] == '' else Allrows[6][2] + idClient = str(random.randint(10000000, 99999999)) if Allrows[5][2] == '' else Allrows[5][2] ET.SubElement(emetteur, "cpf:idClient").text = idClient certificateurs = ET.SubElement(emetteur, "cpf:certificateurs") certificateur = ET.SubElement(certificateurs, "cpf:certificateur") - logging.info("Certificateur %s",idClient) + logging.info(f"Certificateur {idClient}...") # Traitement pour NumClient pour le certificateur idClient2 = str(random.randint(10000000, 99999999)) if Allrows[5][3] == '' else Allrows[5][3] @@ -94,8 +89,8 @@ def create_xml_from_csv(csv_filepath, xml_filepath): certifications = ET.SubElement(certificateur, "cpf:certifications") certification = ET.SubElement(certifications, "cpf:certification") - ET.SubElement(certification, "cpf:type").text = Allrows[6][5] - ET.SubElement(certification, "cpf:code").text = Allrows[6][6] + ET.SubElement(certification, "cpf:type").text = headers[5] + ET.SubElement(certification, "cpf:code").text = headers[6] # Ajout d'un seul passage de certification passage_certifications = ET.SubElement(certification, "cpf:passageCertifications") @@ -162,3 +157,4 @@ def create_xml_from_csv(csv_filepath, xml_filepath): # Appel de la fonction pour créer le fichier XML create_xml_from_csv(csv_file, xml_file) logging.info("Fichier XML créé avec succès.") +