do first transformation
This commit is contained in:
@@ -8,7 +8,6 @@ import re
|
||||
import logging
|
||||
|
||||
import psycopg2
|
||||
from psycopg2 import sql
|
||||
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
@@ -102,22 +101,23 @@ class ASEHandler(FTPHandler):
|
||||
with open(file, 'r') as csvfile:
|
||||
lines = csvfile.readlines()
|
||||
|
||||
units_type = cfg.headers.keys()
|
||||
unit_type = extract_value(units_type, filename, str(lines[0:6]))
|
||||
unit_name = extract_value(cfg.units_name, filename, str(lines[0:6]))
|
||||
tool_name = extract_value(cfg.tools_name, filename, str(lines[0:6]))
|
||||
tool_type = extract_value(cfg.tools_type, filename, str(lines[0:6]))
|
||||
unit_name = extract_value(cfg.units_name, filename, str(lines[0:9]))
|
||||
unit_type = extract_value(cfg.units_type, filename, str(lines[0:9]))
|
||||
tool_name = extract_value(cfg.tools_name, filename, str(lines[0:9]))
|
||||
tool_type = extract_value(cfg.tools_type, filename, str(lines[0:9]))
|
||||
|
||||
conn = conn_db(cfg)
|
||||
|
||||
# Crea un cursore
|
||||
cur = conn.cursor()
|
||||
try:
|
||||
cur.execute("INSERT INTO received (filename, unit_name, unit_type, tool_name, tool_type, tool_data) VALUES (%s,%s,%s,%s,%s,%s)" , (filename, unit_name.upper(), unit_type.upper(), tool_name.upper(), tool_type.upper(), lines))
|
||||
cur.execute(f"INSERT INTO {cfg.dbschema}.{cfg.dbrectable } (filename, unit_name, unit_type, tool_name, tool_type, tool_data) VALUES (%s, %s, %s, %s, %s, %s)", (filename, unit_name.upper(), unit_type.upper(), tool_name.upper(), tool_type.upper(), lines))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
except:
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f'File {file} not loaded. Held in user path.')
|
||||
logging.error(f'{e}')
|
||||
else:
|
||||
os.remove(file)
|
||||
logging.info(f'File {file} loaded: removed.')
|
||||
@@ -161,8 +161,9 @@ class ASEHandler(FTPHandler):
|
||||
conn.close()
|
||||
logging.info("User {} created.".format(user))
|
||||
self.respond('200 SITE ADDU successful.')
|
||||
except:
|
||||
except Exception as e:
|
||||
self.respond('501 SITE ADDU failed.')
|
||||
print(e)
|
||||
|
||||
def ftp_SITE_DELU(self, line):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user