diff --git a/autosort.py b/autosort.py index b141f98..8209949 100644 --- a/autosort.py +++ b/autosort.py @@ -52,8 +52,8 @@ def command(profile, dry_run, verbose): def apply_rules(t, rules): for r in rules: iban = r.get("iban") - name_regex = r.get("name_regex") - desc_regex = r.get("desc_regex") + name_regex = r.get("name") + desc_regex = r.get("description") if iban: if t.iban != iban: diff --git a/cli b/cli index 14373f4..615c1a4 100755 --- a/cli +++ b/cli @@ -3,13 +3,12 @@ import click import os import sys -import sort -import importer -import serve +#import importer +#import serve import autosort -import validate -import info -import report +# import validate +# import info +# import report from helper import build_database_filename, create_dirs from sqlalchemy import create_engine diff --git a/models.py b/models.py index 7ffdba2..48625a9 100644 --- a/models.py +++ b/models.py @@ -15,7 +15,6 @@ class Transaction(Base): iban = Column(String) amount = Column(Integer) description = Column(String) - category_id = Column(Integer, ForeignKey("Category.id")) def is_positive(self): return self.amount > 0 @@ -32,23 +31,11 @@ class Transaction(Base): return "UNKNOWN FORMAT" -class Category(Base): - __tablename__ = "Category" - id = Column(Integer, primary_key=True) - name = Column(String) - transactions = relationship("Transaction", backref="category") - parent_id = Column(Integer, ForeignKey("Category.id")) - children = relationship("Category", backref=backref("parent", remote_side=[id])) +class Tag(Base): + __tablename__ = "Tag" + name = Column(String, primary_key=True) + description = Column(String) + transactions = relationship("Transaction", backref="tags") def __repr__(self): - return f"" - - def is_child(self): - # we are a child if we have zero children - return len(self.children) == 0 - - def full_name(self): - if not self.parent: - return self.name - else: - return f"{self.parent.full_name()}:{self.name}" + return f"" diff --git a/serve.py b/serve.py index 7368757..2b657f5 100644 --- a/serve.py +++ b/serve.py @@ -4,7 +4,7 @@ from helper import get_session, format_amount from datetime import datetime from sqlalchemy import func import click -from models import Transaction, Category +from models import Transaction, Tag session = None app = Flask(__name__) diff --git a/sort.py b/sort.py deleted file mode 100644 index 59e60f0..0000000 --- a/sort.py +++ /dev/null @@ -1,49 +0,0 @@ -#! /usr/bin/env python3 -from models import Transaction -from helper import get_session, add_category, get_list_of_bookable_categories -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) - categories = get_list_of_bookable_categories(session) - category_lookup = {c.full_name(): c.id for c in categories} - category_names = FuzzyWordCompleter([c.full_name() for c in categories]) - - unsorted = session.query(Transaction).filter(Transaction.category_id == 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("Category: ", completer=category_names, complete_while_typing=True) - except KeyboardInterrupt: - print("Goodbye") - sys.exit(0) - - if select == "": - print("Skipping") - continue - - cat_id = category_lookup.get(select, None) - if not cat_id: - print(f"Creating new category '{select}'") - cat_id = add_category(select, profile, session) - # Update the list of categories - categories = get_list_of_bookable_categories(session) - category_lookup = {c.full_name(): c.id for c in categories} - category_names = FuzzyWordCompleter([c.full_name() for c in categories]) - - t.category_id = cat_id - session.add(t) - session.commit() - - print("-" * 20)