diff --git a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py index 40001816f..9967a3382 100644 --- a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py @@ -1,8 +1,15 @@ import csv import os +import sys import oracledb +dictDescriptionIbanPa = {} +with open(sys.argv[1]) as csv_file: + csv_reader = csv.reader(csv_file, delimiter=';') + for row in csv_reader: + dictDescriptionIbanPa.update({(row[1], row[3]): row[7]}) + connection = oracledb.connect( dsn=os.environ['SPRING_DATASOURCE_HOST'], port=os.environ['SPRING_DATASOURCE_PORT'], @@ -16,11 +23,14 @@ csvwriter = csv.writer(result, delimiter=',') # Process data rows for row in csvreader: - cursor.execute(f"Select id_dominio from NODO4_CFG.pa where obj_id={row[0]}") + cursor.execute(""" + Select id_dominio from NODO4_CFG.pa where obj_id=:obj_id + """, obj_id=row[0]) result_set = cursor.fetchall() if(result_set == ''): print(f"Problem with {row[1]}") - rowToWrite = [row[4], result_set[0][0], row[1], "ENABLED", row[2], row[3]] + continue + rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "N/A", row[2], row[3], row[4]] csvwriter.writerow(rowToWrite) cursor.close() diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 95fd2e8ec..f7ace80b0 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -3,22 +3,17 @@ thisdictDate = {} thisdictPa = {} -entries = [] -duplicate_entries = [] with open('./IbanCsv/Iban_Master_output.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 for row in csv_reader: - if line_count == 0: - line_count += 1 - else: - if(thisdictDate.get(row[2]) != None): - if(datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") > datetime.strptime((row[4]), "%Y-%m-%d %H:%M:%S")): - thisdictDate.update({row[2]: row[4]}) - thisdictPa.update({row[2]: row[1]}) - else: + if(thisdictDate.get(row[2]) != None): + if(datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") > datetime.strptime((row[4]), "%Y-%m-%d %H:%M:%S")): thisdictDate.update({row[2]: row[4]}) thisdictPa.update({row[2]: row[1]}) + else: + thisdictDate.update({row[2]: row[4]}) + thisdictPa.update({row[2]: row[1]}) + with open('./IbanCsv/Iban_Master_output.csv', 'r', newline='') as source, open('./IbanCsv/Iban_output.csv', 'w', newline='') as result: csvreader = csv.reader(source, delimiter=',') @@ -26,11 +21,7 @@ # Process data rows for row in csvreader: - new_date = '' - if(row[4] != ''): - d = datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") - new_date = d.strftime("%Y-%m-%d %H:%M:%S") if(thisdictPa.get(row[2]) != None): - rowToWrite = [row[2], thisdictPa.get(row[2]), row[0], new_date] + rowToWrite = [row[2], thisdictPa.get(row[2]), row[6]] thisdictPa.pop(row[2], None) csvwriter.writerow(rowToWrite) diff --git a/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py b/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py index 458f9f19c..e083b03a9 100644 --- a/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py @@ -1,7 +1,5 @@ import os -import csv import oracledb -import sys connection = oracledb.connect( dsn=os.environ['SPRING_DATASOURCE_HOST'], @@ -11,7 +9,7 @@ ) cursor = connection.cursor() -cursor.execute(f"INSERT INTO NODO4_CFG.iban_attributes (ATTRIBUTE_NAME, ATTRIBUTE_DESCRIPTION) VALUES ('0201138TS', 'Canone Unico Patrimoniale - CORPORATE (0201138TS)')") +cursor.execute("INSERT INTO NODO4_CFG.iban_attributes (ATTRIBUTE_NAME, ATTRIBUTE_DESCRIPTION) VALUES ('0201138TS', 'Canone Unico Patrimoniale - CORPORATE (0201138TS)')") connection.commit() cursor.close() diff --git a/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py b/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py index 2ee93c730..3639aecde 100644 --- a/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py @@ -1,6 +1,6 @@ import csv import os - +import numpy as np import oracledb connection = oracledb.connect( @@ -12,10 +12,11 @@ cursor = connection.cursor() data = [] with open('./IbanCsv/Iban_Master_output.csv') as csv_file: - data = list(csv.reader(csv_file)) + data = np.array(list(csv.reader(csv_file))) +data_slice = data[:, :6] cursor.executemany(""" INSERT INTO NODO4_CFG.iban_master (description, fk_pa, fk_iban, state, validity_date, inserted_date) - VALUES (:1, (Select obj_id from NODO4_CFG.pa where id_dominio = :2), (Select obj_id from NODO4_CFG.iban where iban = :3), :4,to_timestamp(:5,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(:6,'YYYY-MM-DD HH24:MI:SS'))""", data) + VALUES (:1, (Select obj_id from NODO4_CFG.pa where id_dominio = :2), (Select obj_id from NODO4_CFG.iban where iban = :3), :4,to_timestamp(:5,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(:6,'YYYY-MM-DD HH24:MI:SS'))""", data_slice.tolist()) connection.commit() cursor.close() connection.close() diff --git a/scripts/utils/pythonExportIban/exportingIbanToDB.py b/scripts/utils/pythonExportIban/exportingIbanToDB.py index 751b028a5..9d1b5a1a6 100644 --- a/scripts/utils/pythonExportIban/exportingIbanToDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanToDB.py @@ -15,7 +15,7 @@ data = list(csv.reader(csv_file)) cursor.executemany(""" INSERT INTO NODO4_CFG.IBAN (IBAN, FISCAL_CODE, DESCRIPTION, DUE_DATE) - VALUES (:1, :2, :3, to_timestamp(:4,'YYYY-MM-DD HH24:MI:SS.FF6'))""", data) + VALUES (:1, :2, :3, ADD_MONTHS(CURRENT_TIMESTAMP, 12))""", data) connection.commit() cursor.close() connection.close() diff --git a/scripts/utils/pythonExportIban/populate_tables.sh b/scripts/utils/pythonExportIban/populate_tables.sh index 1e36542f5..3cbc344e6 100755 --- a/scripts/utils/pythonExportIban/populate_tables.sh +++ b/scripts/utils/pythonExportIban/populate_tables.sh @@ -16,7 +16,7 @@ sed -i "s/[']//g" ./IbanCsv/IbanView.csv echo "All ' eliminated" -python3 exporterIbanMasterToCsv.py +python3 exporterIbanMasterToCsv.py $PDA_CSV_FILE python3 exporterIbanToCsv.py @@ -30,7 +30,9 @@ python3 exportingIbanMastertoDB.py echo "Populated Iban Master table" -python3 exportingIbanAttributesToDB.py $PDA_CSV_FILE +python3 exportingIbanAttributesToDB.py + +python3 exportingIbanAttributesMasterToDB.py $PDA_CSV_FILE echo "Populated Iban Attributes and Iban Attributes Master table"