#!/usr/bin/python2 # -*- coding: utf-8 -*- # # Identification des comptes non compliants suite à une réconciliation # # ---------------------------------------------------------------------- import csv import sys import os CSVDELIMITER="," # Extraction d'une valeur entre tags def extract_xml_tag(ligne, tag): start_tag = "<" + tag + ">" end_tag = "" start_idx = ligne.find(start_tag) + len(start_tag) end_idx = ligne.find(end_tag) valeur = ligne[start_idx:end_idx] return valeur # Extraction d'un attribut (sur le name) def extract_name(ligne): name_tag=' 0: start_idx = ligne.find(start_tag, start_pos) + len(start_tag) end_idx = ligne.find(end_tag, start_idx) start_pos = end_idx + len(end_tag) valeur = ligne[start_idx:end_idx] att_parts = valeur.split('"') # print(att_parts) att_name = att_parts[1] # if att_name != "AttributeChangeOperation" and att_name != "accountServiceProfile": if att_name != "accountServiceProfile": if "AttributeChangeOperation.operation.add" in valeur: att_value = extract_name(valeur) elts[att_value] = att_value elif att_name != "AttributeChangeOperation" : att_value = extract_xml_tag(valeur, "Scalar") # print("Attribute Name : " + att_name + " : value = " + att_value) elts[att_name] = att_value retour = elts["account"] for attrib in elts: if attrib != "account": retour = retour + ";" + attrib return retour # # ------------ MAIN ----------- # print('Starting ' + sys.argv[0] + ' program') # # Saisie et contrôle du fichier CSV # if len(sys.argv) == 2: csvfilename = sys.argv[1] else: print ('ERREUR : veuillez saisir un nom de fichier CSV') # csvfilename="/tmp/18403.csv" exit() # Est-ce qu'on sait lire le fichier ? if os.access(csvfilename, os.R_OK): print('File ' + csvfilename + ' is readable') else: print ('ERREUR : impossible de lire le fichier ' + csvfilename) exit() nb_ligne=0 nb_disallowed = 0 print ("DISALLOWED ACCOUNTS") csvfile = open(csvfilename,'r') csvreader = csv.DictReader(csvfile, delimiter=CSVDELIMITER) for row in csvreader: nb_ligne = nb_ligne + 1 # Creation apres l'entete if nb_ligne > 1: if "DISALLOWEDACCOUNTS" in row["DATA_ID"]: # print(row) # Recuperation du compte nb_disallowed = nb_disallowed + 1 print(extract_xml_tag(row['SMALL_NEW_DATA'], "Scalar")) print("\nNombre de comptes non autorisés : " + str(nb_disallowed)) csvfile.close() print("NONCOMPLIANTACCOUNTS") nb_noncompliant=0 csvfile = open(csvfilename,'r') csvreader = csv.DictReader(csvfile, delimiter=CSVDELIMITER) for row in csvreader: nb_ligne = nb_ligne + 1 # Creation apres l'entete if nb_ligne > 1: if "NONCOMPLIANTACCOUNTS" in row["DATA_ID"]: # print(row) # Recuperation du compte nb_noncompliant = nb_noncompliant + 1 if row['SMALL_NEW_DATA'] != '': print(extract_attributes(row['SMALL_NEW_DATA'])) print("\nNombre de comptes non conformes : " + str(nb_noncompliant)) csvfile.close()