Notify user if fastai does not exist and exit early if there are no transactions to predict.

This commit is contained in:
2024-06-15 18:14:03 -04:00
parent c6b3e121b6
commit 886bcdbdd1

View File

@@ -16,15 +16,17 @@ def get_sort_categories():
from fastai.text.all import load_learner from fastai.text.all import load_learner
learn = load_learner("export.pkl") learn = load_learner("export.pkl")
except ModuleNotFoundError: except ModuleNotFoundError:
pass user_input = input("No fastai module. Type yes to continue anyway.")
except FileNotFoundError: if user_input.strip().lower() != "yes":
pass raise Exception("fastai module missing")
return sort_categories return sort_categories
def add_account2(transactions: List[Transaction], categories: List[str]): def add_account2(transactions: List[Transaction], categories: List[str]):
unmapped_transactions = filter(lambda t: t.account2 == UNKNOWN_CATEGORY, transactions) unmapped_transactions = list(filter(lambda t: t.account2 == UNKNOWN_CATEGORY, transactions))
if len(unmapped_transactions) == 0:
return
sort_categories = get_sort_categories() sort_categories = get_sort_categories()
for t in unmapped_transactions: for t in unmapped_transactions:
sort_categories(t.row, categories) sort_categories(t.row, categories)