Add a ynab config edit command

This commit is contained in:
Gabriel Augendre 2020-02-22 15:34:40 +01:00
parent 6d2b2b5b06
commit 245da78a41
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 27 additions and 2 deletions

View file

@ -2,6 +2,7 @@ import click
import ofx_processor.bpvf_processor.main as bpvf import ofx_processor.bpvf_processor.main as bpvf
import ofx_processor.revolut_processor.main as revolut import ofx_processor.revolut_processor.main as revolut
from ofx_processor.utils import ynab
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
@ -14,6 +15,7 @@ def cli():
cli.add_command(bpvf.cli, name="bpvf") cli.add_command(bpvf.cli, name="bpvf")
cli.add_command(revolut.cli, name="revolut") cli.add_command(revolut.cli, name="revolut")
cli.add_command(ynab.config, name="config")
if __name__ == "__main__": if __name__ == "__main__":
cli() cli()

View file

@ -21,12 +21,31 @@ def get_default_config():
return default_config return default_config
def get_config_file_name():
config_file = os.path.join(DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_FILENAME)
return config_file
@click.group()
def config():
pass
@click.command()
def edit_config():
config_file = get_config_file_name()
click.edit(filename=config_file)
config.add_command(edit_config, "edit")
def push_transactions(transactions, account): def push_transactions(transactions, account):
if not transactions: if not transactions:
click.secho("No transaction, nothing to do.", fg="yellow") click.secho("No transaction, nothing to do.", fg="yellow")
return return
config = configparser.ConfigParser() config = configparser.ConfigParser()
config_file = os.path.join(DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_FILENAME) config_file = get_config_file_name()
if not os.path.isfile(config_file): if not os.path.isfile(config_file):
os.makedirs(DEFAULT_CONFIG_DIR, exist_ok=True) os.makedirs(DEFAULT_CONFIG_DIR, exist_ok=True)
config = get_default_config() config = get_default_config()
@ -56,7 +75,11 @@ def push_transactions(transactions, account):
matched_id = transaction["matched_transaction_id"] matched_id = transaction["matched_transaction_id"]
if not matched_id or matched_id not in created: if not matched_id or matched_id not in created:
created.add(transaction["id"]) created.add(transaction["id"])
click.secho(f"{len(created)} transactions created in YNAB.", fg="green", bold=True)
if created:
click.secho(
f"{len(created)} transactions created in YNAB.", fg="green", bold=True
)
duplicates = data["duplicate_import_ids"] duplicates = data["duplicate_import_ids"]
if duplicates: if duplicates: