Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagopa 1334 sviluppo iban modifica gestione due date e descrizione #264

14 changes: 12 additions & 2 deletions scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py
Original file line number Diff line number Diff line change
@@ -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'],
Expand All @@ -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()
Expand Down
23 changes: 7 additions & 16 deletions scripts/utils/pythonExportIban/exporterIbanToCsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,25 @@

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=',')
csvwriter = csv.writer(result, delimiter=',')

# 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)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import csv
import oracledb
import sys

connection = oracledb.connect(
dsn=os.environ['SPRING_DATASOURCE_HOST'],
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions scripts/utils/pythonExportIban/exportingIbanMastertoDB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import csv
import os

import numpy as np
import oracledb

connection = oracledb.connect(
Expand All @@ -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()
2 changes: 1 addition & 1 deletion scripts/utils/pythonExportIban/exportingIbanToDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions scripts/utils/pythonExportIban/populate_tables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

Expand Down
Loading