fattureCCSR: added filepicker and filedialog for input and output files. Started working on exceptions handling.

Signed-off-by: Ettore Dreucci <ettore.dreucci@gmail.com>
This commit is contained in:
2020-11-26 10:41:00 +01:00
parent 71e9709b3d
commit 850505cdf9
5 changed files with 54 additions and 83 deletions

View File

@@ -1,10 +1,13 @@
"""This script ask for an input file and an output file and generates the TRAF2000 records from a .csv or .xml"""
"""ask for an input file and an output file and generates the TRAF2000 records from a .csv or .xml"""
import os
import datetime
import csv
import xml.etree.ElementTree
import unidecode
import exc
def import_csv(csv_file_path):
"""Return a dict containing the invoices info"""
fatture = dict()
@@ -89,8 +92,18 @@ def import_xml(xml_file_path):
return fatture
def convert(fatture, out_file_path):
def convert(input_file_path, out_file_path):
"""Output to a file the TRAF2000 records"""
input_file_ext = os.path.splitext(input_file_path)[1]
if input_file_ext == ".csv":
fatture = import_csv(input_file_path)
elif input_file_ext == ".xml":
fatture = import_xml(input_file_path)
else:
raise exc.WrongFileExtension("Expected .csv or .xml but received " + input_file_ext)
with open(out_file_path, "w") as traf2000_file:
print("Note di credito:\n")
@@ -263,4 +276,4 @@ def convert(fatture, out_file_path):
linea = ''.join(linea) + '\n'
traf2000_file.write(linea)
traf2000_file.write(linea)