Implemented info command
This commit is contained in:
parent
0f5bb8f04d
commit
3790ab6c65
3 changed files with 36 additions and 0 deletions
2
cli
2
cli
|
@ -7,6 +7,7 @@ import sort
|
||||||
import importer
|
import importer
|
||||||
import serve
|
import serve
|
||||||
import autosort
|
import autosort
|
||||||
|
import info
|
||||||
|
|
||||||
from helper import build_database_filename, create_dirs
|
from helper import build_database_filename, create_dirs
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
@ -40,4 +41,5 @@ if __name__ == '__main__':
|
||||||
cli.add_command(importer.command)
|
cli.add_command(importer.command)
|
||||||
cli.add_command(serve.command)
|
cli.add_command(serve.command)
|
||||||
cli.add_command(autosort.command)
|
cli.add_command(autosort.command)
|
||||||
|
cli.add_command(info.command)
|
||||||
cli()
|
cli()
|
||||||
|
|
|
@ -42,6 +42,9 @@ 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 list_profiles():
|
||||||
|
files = os.listdir(f"{DATA_DIR}/databases")
|
||||||
|
return [x.split(".")[0] for x in files]
|
||||||
|
|
||||||
def get_session(profile_name):
|
def get_session(profile_name):
|
||||||
if not profile_name:
|
if not profile_name:
|
||||||
|
|
31
info.py
Normal file
31
info.py
Normal file
|
@ -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("----------")
|
Loading…
Add table
Reference in a new issue