This commit is contained in:
Felix Breidenstein 2020-10-18 23:11:29 +02:00
parent 9154039644
commit 9f6293872a
5 changed files with 58 additions and 8 deletions

View file

@ -53,7 +53,7 @@ def apply_rules(t, rules):
continue
if desc_regex:
if not re.search(desc_regext.description):
if not re.search(desc_regex, t.description):
continue
return r["tags"].split(",")

12
cli
View file

@ -8,8 +8,9 @@ import importer
import serve
import autosort
import validate
# import info
# import report
import info
import sort
#import report
from helper import build_database_filename, create_dirs, build_rules_filename
from sqlalchemy import create_engine
@ -27,6 +28,8 @@ def cli():
@cli.command(name="init")
@click.argument("profile_name", required=True)
def init(profile_name):
create_dirs()
db_path = build_database_filename(profile_name)
rule_path = build_rules_filename(profile_name)
@ -44,12 +47,11 @@ def init(profile_name):
if __name__ == '__main__':
create_dirs()
# cli.add_command(sort.command)
cli.add_command(sort.command)
cli.add_command(importer.command)
cli.add_command(serve.command)
cli.add_command(autosort.command)
cli.add_command(validate.command)
# cli.add_command(info.command)
cli.add_command(info.command)
# cli.add_command(report.command)
cli()

View file

@ -29,7 +29,7 @@ def command(profile, year):
for sc in sub_categories:
transactions = session.query(Transaction).filter(Transaction.category_id == sc.id).all()
data[mc.name][sc.name] = format_amount(sum([x.amount for x in transactions]))
context = {"year": year, "data": data}
tpl = template("views/report.tpl", context)

49
sort.py Normal file
View file

@ -0,0 +1,49 @@
#! /usr/bin/env python3
from models import Transaction, Tag
from helper import get_session, create_tag
import sys
import click
from prompt_toolkit.completion import FuzzyWordCompleter
from prompt_toolkit.shortcuts import prompt
@click.command(name="sort")
@click.option("--profile", "-p")
def command(profile):
session = get_session(profile)
tags = session.query(Tag).all()
tag_names = FuzzyWordCompleter([x.name for x in tags])
tag_lookup = {tag.name: tag for tag in tags}
unsorted = session.query(Transaction).filter(Transaction.tags == None).all()
print("Found {} unsorted transcations".format(len(unsorted)))
for t in unsorted:
print(" Name: {}".format(t.name))
print(" VWZ: {}".format(t.description))
print("Betrag: {}".format(t.amount / 100))
try:
select = prompt("Tag: ", completer=tag_names, complete_while_typing=True)
except KeyboardInterrupt:
print("Goodbye")
sys.exit(0)
if select == "":
print("Skipping")
continue
tag = tag_lookup.get(select, None)
if not tag:
print(f"Creating new category '{select}'")
tag = create_tag(select, profile, session)
tags = session.query(Tag).all()
tag_names = FuzzyWordCompleter([x.name for x in tags])
tag_lookup = {tag.name: tag for tag in tags}
t.tags.append(tag)
session.add(t)
session.commit()
print("-" * 20)

View file

@ -56,7 +56,6 @@ def command():
except:
print(cf.red(f" Invalid IBAN: '{rule.get('iban')}'"))
print(cf.green(f" All rules are valid"))
else:
print(cf.red(f" The rule file doesn't exists"))