Formatting
This commit is contained in:
parent
48ba732038
commit
0f5bb8f04d
2 changed files with 9 additions and 6 deletions
12
autosort.py
12
autosort.py
|
@ -11,6 +11,7 @@ import colorful as cf
|
||||||
from prompt_toolkit.completion import FuzzyWordCompleter
|
from prompt_toolkit.completion import FuzzyWordCompleter
|
||||||
from prompt_toolkit.shortcuts import prompt
|
from prompt_toolkit.shortcuts import prompt
|
||||||
|
|
||||||
|
|
||||||
def print_verbose(verbose, string):
|
def print_verbose(verbose, string):
|
||||||
if verbose:
|
if verbose:
|
||||||
print(string)
|
print(string)
|
||||||
|
@ -31,17 +32,17 @@ def command(profile, dry_run, verbose):
|
||||||
for t in unsorted:
|
for t in unsorted:
|
||||||
cat_name = apply_rules(t, rules)
|
cat_name = apply_rules(t, rules)
|
||||||
if cat_name:
|
if cat_name:
|
||||||
short_name = (t.name[:25] if len(t.name)>25 else t.name)
|
short_name = t.name[:25] if len(t.name) > 25 else t.name
|
||||||
short_desc = (t.description[:45] if len(t.description)>50 else t.description)
|
short_desc = t.description[:45] if len(t.description) > 50 else t.description
|
||||||
print_verbose(verbose,"{:<25} | {:<50}| {:>10}€".format(short_name, short_desc, t.amount/100))
|
print_verbose(verbose, "{:<25} | {:<50}| {:>10}€".format(short_name, short_desc, t.amount / 100))
|
||||||
print_verbose(verbose, cf.green(f"Matched '{cat_name}'"))
|
print_verbose(verbose, cf.green(f"Matched '{cat_name}'"))
|
||||||
cat_id = session.query(Category).filter(Category.name == cat_name).first()
|
cat_id = session.query(Category).filter(Category.name == cat_name).first()
|
||||||
if not cat_id:
|
if not cat_id:
|
||||||
cat_id = add_category(cat_name, profile, session)
|
cat_id = add_category(cat_name, profile, session)
|
||||||
matched +=1
|
matched += 1
|
||||||
t.category_id = cat_id
|
t.category_id = cat_id
|
||||||
session.add(t)
|
session.add(t)
|
||||||
print_verbose(verbose, "-"*90)
|
print_verbose(verbose, "-" * 90)
|
||||||
|
|
||||||
print(f"Automatically matched {matched} transactions")
|
print(f"Automatically matched {matched} transactions")
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
|
@ -67,4 +68,3 @@ def apply_rules(t, rules):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return r["category"]
|
return r["category"]
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,11 @@ def create_dirs():
|
||||||
def build_database_filename(profile_name):
|
def build_database_filename(profile_name):
|
||||||
return f"{DATA_DIR}/databases/{profile_name}.db"
|
return f"{DATA_DIR}/databases/{profile_name}.db"
|
||||||
|
|
||||||
|
|
||||||
def build_rules_filename(profile_name):
|
def build_rules_filename(profile_name):
|
||||||
return f"{DATA_DIR}/rules/{profile_name}.yaml"
|
return f"{DATA_DIR}/rules/{profile_name}.yaml"
|
||||||
|
|
||||||
|
|
||||||
def check_single_profile():
|
def check_single_profile():
|
||||||
files = os.listdir(f"{DATA_DIR}/databases")
|
files = os.listdir(f"{DATA_DIR}/databases")
|
||||||
if len(files) == 1:
|
if len(files) == 1:
|
||||||
|
@ -40,6 +42,7 @@ def check_single_profile():
|
||||||
print("--profile is required when you have more than one database.")
|
print("--profile is required when you have more than one database.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def get_session(profile_name):
|
def get_session(profile_name):
|
||||||
if not profile_name:
|
if not profile_name:
|
||||||
profile_name = check_single_profile()
|
profile_name = check_single_profile()
|
||||||
|
|
Loading…
Add table
Reference in a new issue