forked from gaugendre/ofx-processor
Increase options flexibility for BPVF and revolut
This commit is contained in:
parent
9dee12d2c5
commit
c91991169c
2 changed files with 34 additions and 16 deletions
|
@ -34,12 +34,20 @@ def process_name_and_memo(transaction):
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("ofx_filename")
|
@click.argument("ofx_filename")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--ynab/--file-only",
|
"--ynab/--no-ynab",
|
||||||
"push_to_ynab",
|
"push_to_ynab",
|
||||||
default=False,
|
default=True,
|
||||||
help="Push data directly to YNAB instead of just writing a file.",
|
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()
|
parser = OFXTree()
|
||||||
try:
|
try:
|
||||||
parser.parse(ofx_filename)
|
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")
|
click.secho(f"Processed {len(ynab_transactions)} transactions total.", fg="blue")
|
||||||
|
|
||||||
header = str(make_header(version=102))
|
if output_file:
|
||||||
root = ofx.to_etree()
|
header = str(make_header(version=102))
|
||||||
data = ElementTree.tostring(root).decode()
|
root = ofx.to_etree()
|
||||||
processed_file = os.path.join(os.path.dirname(ofx_filename), "processed.ofx")
|
data = ElementTree.tostring(root).decode()
|
||||||
with open(processed_file, "w") as f:
|
processed_file = os.path.join(os.path.dirname(ofx_filename), "processed.ofx")
|
||||||
f.write(header + data)
|
with open(processed_file, "w") as f:
|
||||||
click.secho("{} written".format(processed_file), fg="green")
|
f.write(header + data)
|
||||||
|
click.secho("{} written".format(processed_file), fg="green")
|
||||||
|
|
||||||
if push_to_ynab:
|
if push_to_ynab:
|
||||||
ynab.push_transactions(ynab_transactions, "bpvf")
|
ynab.push_transactions(ynab_transactions, "bpvf")
|
||||||
|
|
|
@ -38,11 +38,20 @@ def process_outflow(line):
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("csv_filename")
|
@click.argument("csv_filename")
|
||||||
@click.option(
|
@click.option(
|
||||||
"--ynab/--file-only",
|
"--ynab/--no-ynab",
|
||||||
default=False,
|
"push_to_ynab",
|
||||||
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(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 = []
|
formatted_data = []
|
||||||
ynab_transactions = []
|
ynab_transactions = []
|
||||||
transaction_ids = defaultdict(int)
|
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")
|
processed_file = os.path.join(os.path.dirname(csv_filename), "processed.csv")
|
||||||
with open(processed_file, "w") as f:
|
with open(processed_file, "w") as f:
|
||||||
writer = csv.DictWriter(
|
writer = csv.DictWriter(
|
||||||
|
|
Loading…
Reference in a new issue