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",
|
"debit",
|
||||||
"credit",
|
"credit",
|
||||||
"additional_parser",
|
"additional_parser",
|
||||||
|
"category",
|
||||||
"VISA",
|
"VISA",
|
||||||
"MasterCard",
|
"MasterCard",
|
||||||
"AmericanExpress",
|
"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]
|
options: dict = cfg[bank][creditcard]
|
||||||
bank += creditcard
|
bank += creditcard
|
||||||
|
|
||||||
|
if args["category"]:
|
||||||
|
options["category"] = args["category"][0]
|
||||||
|
|
||||||
if options.get("additional_parser"):
|
if options.get("additional_parser"):
|
||||||
parser = getattr(import_module("pfbudget.parsers"), bank)
|
parser = getattr(import_module("pfbudget.parsers"), bank)
|
||||||
transactions = parser(filename, bank, options).parse()
|
transactions = parser(filename, bank, options).parse()
|
||||||
@ -130,7 +134,12 @@ class Parser:
|
|||||||
value = utils.parse_decimal(line[index.value])
|
value = utils.parse_decimal(line[index.value])
|
||||||
if index.negate:
|
if index.negate:
|
||||||
value = -value
|
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:
|
if options.additional_parser:
|
||||||
func(transaction)
|
func(transaction)
|
||||||
|
|||||||
@ -66,6 +66,7 @@ def argparser() -> argparse.ArgumentParser:
|
|||||||
p_parse.add_argument("path", nargs="+", type=str)
|
p_parse.add_argument("path", nargs="+", type=str)
|
||||||
p_parse.add_argument("--bank", nargs=1, type=str)
|
p_parse.add_argument("--bank", nargs=1, type=str)
|
||||||
p_parse.add_argument("--creditcard", 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)
|
p_parse.set_defaults(func=parse)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user