From 7065e14303b3d0e383767136504573e60d602bd1 Mon Sep 17 00:00:00 2001 From: Cedric Schmeits Date: Sun, 25 Dec 2022 13:26:31 +0100 Subject: [PATCH] Converted to python3 and added delimiter combobox --- gui.glade | 215 ++++++++++++++++++++++++++++++----------------------- gui.py | 21 ++++-- ing2ofx.py | 21 +++--- 3 files changed, 146 insertions(+), 111 deletions(-) diff --git a/gui.glade b/gui.glade index c8d20d0..5d98811 100644 --- a/gui.glade +++ b/gui.glade @@ -1,34 +1,33 @@ - + - False - dialog - ING2OFX + False + dialog + ING2OFX 1.0 Arie van Dobben https://github.com/chmistry/ing2ofx - Visit github page + Visit github page Arie van Dobben images.png - - gpl-3-0 + gpl-3-0 - False + False vertical 2 - False - end + False + end False True - end + end 0 @@ -46,39 +45,39 @@ - 400 - False - center - 700 - 500 + 400 + False + center + 700 + 500 images.png True - False + False vertical True - False + False True - False + False _File - True + True True - False + False gtk-quit True - False - True - True + False + True + True @@ -89,20 +88,20 @@ True - False + False _Help - True + True True - False + False gtk-about True - False - True - True + False + True + True @@ -120,19 +119,19 @@ True - False + False start - queue + queue vertical - start + start Convert decimal separator to dots (.) True - True - False + True + False 0 - True + True False @@ -144,10 +143,10 @@ Convert dates with dd-mm-yyyy notation to yyyymmdd True - True - False + True + False 0 - True + True False @@ -155,6 +154,49 @@ 1 + + + True + False + 8 + + + True + False + CVS file delimiter: + + + False + True + 0 + + + + + True + False + 0 + + Comma (,) + Semicolon (;) + + + + False + False + 1 + + + + + True + True + 2 + + + + + False @@ -163,62 +205,57 @@ + True - False + False True - False + False filefilter1 - 1 - 2 - 1 - 1 + 1 + 2 True - False + False end 8 CSV file: end - 0 - 2 - 1 - 1 + 0 + 2 Output filename same as input True - True - False + True + False 0 0.49000000953674316 True - True + True - 0 - 0 - 1 - 1 + 0 + 0 True - False + False end center 8 @@ -226,52 +263,44 @@ end - 1 - 0 - 1 - 1 + 1 + 0 True - False + False end 8 Output folder: - 0 - 1 - 1 - 1 + 0 + 1 True - False + False select-folder Select a Folder - 1 - 1 - 1 - 1 + 1 + 1 True - True + True False - 2 - 0 - 1 - 1 + 2 + 0 @@ -290,18 +319,18 @@ True - True - in + True + in True - True - natural + True + natural False - 1 - 1 + 1 + 1 1 - False + False textbuffer1 @@ -315,16 +344,16 @@ True - False + False 14 True - center + center Convert True - True - True + True + True @@ -343,11 +372,11 @@ True - False - 10 - 10 - 6 - 6 + False + 10 + 10 + 6 + 6 vertical 2 diff --git a/gui.py b/gui.py index 109138c..8865db4 100755 --- a/gui.py +++ b/gui.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # gui.py @@ -51,21 +51,24 @@ def on_button1_clicked(self, button1): outdir = self.gui.builder.get_object( "filechooserbutton2").get_current_folder() if self.gui.builder.get_object("checkbutton3").get_active(): - outfile = os.path.basename(csvfile) + outfile = os.path.basename(csvfile).replace("csv", "ofx").replace("CSV", "OFX") else: outfile = self.gui.builder.get_object("entry1").get_text() - self.gui.push_text("Input:\n\tconvert: " + str(convert) + - "\n\t convert_date: " + str(convert_date) + + self.gui.push_text("Input:\n\tconvert: " + str(convert) + + "\n\t convert_date: " + str(convert_date) + "\n\t csvfile: " + str(csvfile) + - "\n\t outdir: " + str(outdir) + + "\n\t outdir: " + str(outdir) + "\n\t outfile: " + str(outfile)) + delimiter = self.gui.builder.get_object("comboboxDelimiter").get_active_id() + self.gui.push_text(f"delimiter: {delimiter}") + convert = CsvConverter( csvfile=csvfile, outfile=outfile, dir=outdir, convert=convert, - convert_date=convert_date) + convert_date=convert_date, delimiter=delimiter) - self.gui.push_text(convert.stats_transactions + + self.gui.push_text(convert.stats_transactions + "\n\t" + convert.stats_in + "\n\t" + convert.stats_out) break @@ -123,12 +126,13 @@ def __init__(self): self.dir = None self.convert = None self.convert_date = None + self.delimiter = None class CsvConverter: def __init__(self, csvfile, outfile, dir='./ofx', convert=False, - convert_date=False): + convert_date=False, delimiter=','): self.args = Arguments_container() self.args.outfile = outfile @@ -136,6 +140,7 @@ def __init__(self, csvfile, outfile, dir='./ofx', convert=False, self.args.dir = dir self.args.convert = convert self.args.convert_date = convert_date + self.args.delimiter = delimiter ofx = ing2ofx.OfxWriter(self.args, gui=True) diff --git a/ing2ofx.py b/ing2ofx.py index ece7f33..8a21836 100755 --- a/ing2ofx.py +++ b/ing2ofx.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # ing2ofx.py @@ -50,9 +50,9 @@ def __init__(self, args): # Keep track of used IDs to prevent double IDs idslist = [] - with open(args.csvfile, 'rb') as csvfile: + with open(args.csvfile, 'r') as csvfile: # Open the csvfile as a Dictreader - csvreader = csv.DictReader(csvfile, delimiter=',', quotechar='"') + csvreader = csv.DictReader(csvfile, delimiter=args.delimiter, quotechar='"') for row in csvreader: # Map ACCOUNT to "Rekening" account = row['Rekening'].replace(" ", "") @@ -250,14 +250,13 @@ def __init__(self, args, gui=True): if not gui: # print some statistics: - print "TRANSACTIONS: " + str(len(csv.transactions)) - print "IN: " + args.csvfile - print "OUT: " + filename + print(f"TRANSACTIONS: {str(len(csv.transactions))}") + print(f"IN: {args.csvfile}") + print(f"OUT: {filename}") else: - self.stats_transactions = "TRANSACTIONS: " + \ - str(len(csv.transactions)) - self.stats_in = "IN: " + args.csvfile - self.stats_out = "OUT: " + filepath + self.stats_transactions = f"TRANSACTIONS: {str(len(csv.transactions))}" + self.stats_in = f"IN: {args.csvfile}" + self.stats_out = f"OUT: {filepath}" if __name__ == "__main__": """ First parse the command line arguments. """ @@ -274,6 +273,8 @@ def __init__(self, args, gui=True): help="Convert decimal separator to dots (.), default is false", action='store_true') parser.add_argument('-b, --convert_date', dest='convert_date', help="Convert dates with dd-mm-yyyy notation to yyyymmdd", action='store_true') + parser.add_argument('-l, --delimiter', dest='delimiter', + help="Delimiter used within CVS file", default=',') args = parser.parse_args() ofx = OfxWriter(args, gui=False)