From c91991169ca54634b2d33e55cfd0c14722b88e9e Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 12 Feb 2020 00:00:46 +0100 Subject: [PATCH] Increase options flexibility for BPVF and revolut --- ofx_processor/bpvf_processor/main.py | 31 ++++++++++++++++--------- ofx_processor/revolut_processor/main.py | 19 +++++++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ofx_processor/bpvf_processor/main.py b/ofx_processor/bpvf_processor/main.py index 115800e..37f70ad 100644 --- a/ofx_processor/bpvf_processor/main.py +++ b/ofx_processor/bpvf_processor/main.py @@ -34,12 +34,20 @@ def process_name_and_memo(transaction): @click.command() @click.argument("ofx_filename") @click.option( - "--ynab/--file-only", + "--ynab/--no-ynab", "push_to_ynab", - default=False, - help="Push data directly to YNAB instead of just writing a file.", + default=True, + help="Push data directly to YNAB.", + show_default=True, ) -def cli(ofx_filename, push_to_ynab): +@click.option( + "--file/--no-file", + "output_file", + default=False, + help="Write a processed file.", + show_default=True, +) +def cli(ofx_filename, push_to_ynab, output_file): parser = OFXTree() try: parser.parse(ofx_filename) @@ -85,13 +93,14 @@ def cli(ofx_filename, push_to_ynab): ) click.secho(f"Processed {len(ynab_transactions)} transactions total.", fg="blue") - header = str(make_header(version=102)) - root = ofx.to_etree() - data = ElementTree.tostring(root).decode() - processed_file = os.path.join(os.path.dirname(ofx_filename), "processed.ofx") - with open(processed_file, "w") as f: - f.write(header + data) - click.secho("{} written".format(processed_file), fg="green") + if output_file: + header = str(make_header(version=102)) + root = ofx.to_etree() + data = ElementTree.tostring(root).decode() + processed_file = os.path.join(os.path.dirname(ofx_filename), "processed.ofx") + with open(processed_file, "w") as f: + f.write(header + data) + click.secho("{} written".format(processed_file), fg="green") if push_to_ynab: ynab.push_transactions(ynab_transactions, "bpvf") diff --git a/ofx_processor/revolut_processor/main.py b/ofx_processor/revolut_processor/main.py index 90c8e31..965a3c8 100644 --- a/ofx_processor/revolut_processor/main.py +++ b/ofx_processor/revolut_processor/main.py @@ -38,11 +38,20 @@ def process_outflow(line): @click.command() @click.argument("csv_filename") @click.option( - "--ynab/--file-only", - default=False, - help="Push data directly to YNAB instead of just writing a file.", + "--ynab/--no-ynab", + "push_to_ynab", + default=True, + help="Push data directly to YNAB.", + show_default=True, ) -def cli(csv_filename, push_to_ynab): +@click.option( + "--file/--no-file", + "output_file", + default=False, + help="Write a processed file.", + show_default=True, +) +def cli(csv_filename, push_to_ynab, output_file): formatted_data = [] ynab_transactions = [] transaction_ids = defaultdict(int) @@ -80,7 +89,7 @@ def cli(csv_filename, push_to_ynab): } ) - if formatted_data: + if output_file and formatted_data: processed_file = os.path.join(os.path.dirname(csv_filename), "processed.csv") with open(processed_file, "w") as f: writer = csv.DictWriter(