Update Accrochage.py

This commit is contained in:
jfontaine35 2024-09-18 17:44:15 +02:00 committed by GitHub
parent 1ab62d50e7
commit fe43a7e232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 13 deletions

View File

@ -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.")