Adds --category index option
Category argument added to allow the parsing of already categorized transaction files. The new option takes an integer to indicate the category index in a transaction row.
This commit is contained in:
parent
ba608093d3
commit
85c0819a44
@ -26,11 +26,12 @@ Options = namedtuple(
|
||||
"debit",
|
||||
"credit",
|
||||
"additional_parser",
|
||||
"category",
|
||||
"VISA",
|
||||
"MasterCard",
|
||||
"AmericanExpress",
|
||||
],
|
||||
defaults=["", "", "", 1, None, Index(), Index(), False, None, None, None],
|
||||
defaults=["", "", "", 1, None, Index(), Index(), False, None, None, None, None],
|
||||
)
|
||||
|
||||
|
||||
@ -54,6 +55,9 @@ def parse_data(db: DBManager, filename: str, args: dict) -> None:
|
||||
options: dict = cfg[bank][creditcard]
|
||||
bank += creditcard
|
||||
|
||||
if args["category"]:
|
||||
options["category"] = args["category"][0]
|
||||
|
||||
if options.get("additional_parser"):
|
||||
parser = getattr(import_module("pfbudget.parsers"), bank)
|
||||
transactions = parser(filename, bank, options).parse()
|
||||
@ -130,7 +134,12 @@ class Parser:
|
||||
value = utils.parse_decimal(line[index.value])
|
||||
if index.negate:
|
||||
value = -value
|
||||
transaction = Transaction(date, text, bank, value)
|
||||
|
||||
if options.category:
|
||||
category = line[options.category]
|
||||
transaction = Transaction(date, text, bank, value, category)
|
||||
else:
|
||||
transaction = Transaction(date, text, bank, value, options.category)
|
||||
|
||||
if options.additional_parser:
|
||||
func(transaction)
|
||||
|
||||
@ -66,6 +66,7 @@ def argparser() -> argparse.ArgumentParser:
|
||||
p_parse.add_argument("path", nargs="+", type=str)
|
||||
p_parse.add_argument("--bank", nargs=1, type=str)
|
||||
p_parse.add_argument("--creditcard", nargs=1, type=str)
|
||||
p_parse.add_argument("--category", nargs=1, type=int)
|
||||
p_parse.set_defaults(func=parse)
|
||||
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user