From e49e8c51f58c9cd52533fdb5e949a3b3bf67afe3 Mon Sep 17 00:00:00 2001 From: Felix Breidenstein Date: Sun, 18 Oct 2020 18:05:05 +0200 Subject: [PATCH] WIP --- autosort.py | 8 ++------ cli | 18 +++++++++--------- helper.py | 30 ++++++------------------------ models.py | 1 - validate.py | 6 ++++++ 5 files changed, 23 insertions(+), 40 deletions(-) diff --git a/autosort.py b/autosort.py index 8209949..e2d2740 100644 --- a/autosort.py +++ b/autosort.py @@ -2,16 +2,12 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base -from models import Category, Transaction +from models import Category, Tag from helper import get_session, add_category, get_rules import sys import click import colorful as cf -from prompt_toolkit.completion import FuzzyWordCompleter -from prompt_toolkit.shortcuts import prompt - - def print_verbose(verbose, string): if verbose: print(string) @@ -25,7 +21,7 @@ def command(profile, dry_run, verbose): session = get_session(profile) rules = get_rules(profile) - unsorted = session.query(Transaction).filter(Transaction.category_id == None).all() + unsorted = session.query(Transaction).filter(Transaction.tags == None).all() print("Found {} unsorted transcations".format(len(unsorted))) new = [] diff --git a/cli b/cli index 615c1a4..8aa219c 100755 --- a/cli +++ b/cli @@ -3,9 +3,9 @@ import click import os import sys -#import importer -#import serve -import autosort +import importer +# import serve +# import autosort # import validate # import info # import report @@ -38,11 +38,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(report.command) + # cli.add_command(serve.command) + # cli.add_command(autosort.command) + # cli.add_command(validate.command) + # cli.add_command(info.command) + # cli.add_command(report.command) cli() diff --git a/helper.py b/helper.py index 283f9a0..d27be6e 100644 --- a/helper.py +++ b/helper.py @@ -24,11 +24,6 @@ def format_amount(cents): return f"{amount:,.2f}" -def get_list_of_bookable_categories(session): - categories = session.query(models.Category).all() - return [c for c in categories if c.is_child()] - - def create_dirs(): for directory in [CONFIG_DIR, DATA_DIR]: try: @@ -90,23 +85,10 @@ def get_rules(profile_name): sys.exit(1) -def create_category(name, parent, profile, session): - c = session.query(models.Category).filter(models.Category.name == name).first() - if not c: - c = models.Category(name=name, parent_id=parent) - session.add(c) +def create_tag(name, profile, session): + t = session.query(models.Tag).filter(models.Tag.name == name).first() + if not t: + c = models.Tag(name=name) + session.add(t) session.commit() - return c.id - - -def add_category(name, profile, session): - parts = name.split(":") - if len(parts) == 1: - return create_category(name, None, profile, session) - else: - for i in range(len(parts) - 1): - parent = parts[i] - child = parts[i + 1] - parent_id = create_category(parent, None, profile, session) - id = create_category(child, parent_id, profile, session) - return id + return t.id diff --git a/models.py b/models.py index 48625a9..9eb68d9 100644 --- a/models.py +++ b/models.py @@ -2,7 +2,6 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, DateTime, ForeignKey from sqlalchemy.orm import relationship, backref -from helper import format_amount Base = declarative_base() diff --git a/validate.py b/validate.py index 5c72090..6f37935 100644 --- a/validate.py +++ b/validate.py @@ -33,24 +33,30 @@ def command(): print(cf.green(" Ruleset is empty")) else: for rule in data: + # TODO: validate tag list + + # validate name regex if rule.get("name"): try: re.compile(rule["name"]) except: print(cf.red(f" Invalid name regex: '{rule.get('name')}'")) + # validate description regex if rule.get("description"): try: re.compile(rule["description"]) except: print(cf.red(f" Invalid description regex: '{rule.get('description')}'")) + # validate IBAN if rule.get("iban"): try: IBAN(rule.get("iban")) 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"))