From 3790ab6c65894e4134b2b867c201a3db024980c5 Mon Sep 17 00:00:00 2001 From: Felix Breidenstein Date: Mon, 30 Mar 2020 00:11:38 +0200 Subject: [PATCH] Implemented info command --- cli | 2 ++ helper.py | 3 +++ info.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 info.py diff --git a/cli b/cli index 7eaf0cf..2ba2533 100755 --- a/cli +++ b/cli @@ -7,6 +7,7 @@ import sort import importer import serve import autosort +import info from helper import build_database_filename, create_dirs from sqlalchemy import create_engine @@ -40,4 +41,5 @@ if __name__ == '__main__': cli.add_command(importer.command) cli.add_command(serve.command) cli.add_command(autosort.command) + cli.add_command(info.command) cli() diff --git a/helper.py b/helper.py index 440b402..0a039bc 100644 --- a/helper.py +++ b/helper.py @@ -42,6 +42,9 @@ def check_single_profile(): print("--profile is required when you have more than one database.") sys.exit(1) +def list_profiles(): + files = os.listdir(f"{DATA_DIR}/databases") + return [x.split(".")[0] for x in files] def get_session(profile_name): if not profile_name: diff --git a/info.py b/info.py new file mode 100644 index 0000000..bc35421 --- /dev/null +++ b/info.py @@ -0,0 +1,31 @@ +#! /usr/bin/env python3 +from sqlalchemy import create_engine +from models import Category, Transaction +from helper import get_session, list_profiles, build_database_filename, build_rules_filename +import sys +import click + +from prompt_toolkit.completion import FuzzyWordCompleter +from prompt_toolkit.shortcuts import prompt + + +@click.command(name="info") +def command(): + for profile in list_profiles(): + session = get_session(profile) + db_path = build_database_filename(profile) + rules_path = build_rules_filename(profile) + + print(f"Profile: {profile}") + print(f" DB: {db_path}") + print(f" Rules: {rules_path}") + + unsorted = session.query(Transaction).filter(Transaction.category_id == None).count() + transactions = session.query(Transaction).count() + categories = session.query(Category).count() + unsorted_percent = round(unsorted / (transactions/100), 1) + + print(f"Transactions: {transactions}") + print(f" Unsorted: {unsorted} ({unsorted_percent}%)") + print(f" Categories: {categories}") + print("----------")