From 93e59b54431051f26eb8e75fdc3f6eb324b28eb9 Mon Sep 17 00:00:00 2001 From: gilgamezh Date: Tue, 2 Apr 2024 18:26:08 +0200 Subject: [PATCH 1/3] Small fix after merge conflicts --- src/ficamp/__main__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ficamp/__main__.py b/src/ficamp/__main__.py index c901d45..5e2881a 100644 --- a/src/ficamp/__main__.py +++ b/src/ficamp/__main__.py @@ -138,13 +138,25 @@ def categorize(engine): print("Session interrupted. Closing.") +def sync(args, engine): + total_per_category = defaultdict(Decimal) + with Session(engine) as session: + statement = select(Tx) + results = session.exec(statement).all() + print(f"Got {len(results)} Tx to report") + for tx in results: + total_per_category[tx.category] += tx.amount + for k, v in total_per_category.items(): + print(k, v) + + def main(): engine = create_engine("sqlite:///ficamp.db") # create DB SQLModel.metadata.create_all(engine) # create tables try: args = cli() if args.command: - args.func(engine) + args.func(args, engine) except KeyboardInterrupt: print("\nClosing") From 926497305a84e30ce6abc5177a5b87b24f0a6687 Mon Sep 17 00:00:00 2001 From: gilgamezh Date: Tue, 2 Apr 2024 18:26:32 +0200 Subject: [PATCH 2/3] include sync --- src/ficamp/__main__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ficamp/__main__.py b/src/ficamp/__main__.py index 5e2881a..2a76a4f 100644 --- a/src/ficamp/__main__.py +++ b/src/ficamp/__main__.py @@ -1,5 +1,6 @@ import argparse from collections import defaultdict +from decimal import Decimal import questionary from dotenv import load_dotenv @@ -39,6 +40,10 @@ def cli() -> argparse.Namespace: ) categorize_parser.set_defaults(func=categorize) + # Subparser for the sync command + categorize_parser = subparsers.add_parser("sync", help="Report transactions") + categorize_parser.set_defaults(func=sync) + args = parser.parse_args() return args @@ -116,7 +121,7 @@ def query_business_category(tx, session): return answer -def categorize(engine): +def categorize(args, engine): """Classify transactions into categories""" try: with Session(engine) as session: From c4b0c7acca784ad243c6e25002a1fa6dbe2db00e Mon Sep 17 00:00:00 2001 From: gilgamezh Date: Tue, 2 Apr 2024 18:47:37 +0200 Subject: [PATCH 3/3] print hints from Gmap --- src/ficamp/__main__.py | 9 +++++++++ src/ficamp/classifier/infer.py | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ficamp/__main__.py b/src/ficamp/__main__.py index 2a76a4f..c2b473c 100644 --- a/src/ficamp/__main__.py +++ b/src/ficamp/__main__.py @@ -6,6 +6,7 @@ from dotenv import load_dotenv from sqlmodel import Session, SQLModel, create_engine, select +from ficamp.classifier.infer import infer_tx_category from ficamp.classifier.keywords import sort_by_keyword_matches from ficamp.classifier.preprocessing import preprocess from ficamp.datastructures import Tx @@ -39,6 +40,11 @@ def cli() -> argparse.Namespace: "categorize", help="Categorize transactions" ) categorize_parser.set_defaults(func=categorize) + categorize_parser.add_argument( + "--hints", + help="Query some APIs to hint the categroy of the Tx", + action="store_true", + ) # Subparser for the sync command categorize_parser = subparsers.add_parser("sync", help="Report transactions") @@ -130,6 +136,9 @@ def categorize(args, engine): print(f"Got {len(results)} Tx to categorize") for tx in results: print(f"Processing {tx}") + hinted_category = infer_tx_category(tx) + if hinted_category: + print(f"Hint! This seems to be category: {hinted_category}") tx_category = query_business_category(tx, session) if tx_category: print(f"Saving category for {tx.concept}: {tx_category}") diff --git a/src/ficamp/classifier/infer.py b/src/ficamp/classifier/infer.py index b99a10a..9dd9fd9 100644 --- a/src/ficamp/classifier/infer.py +++ b/src/ficamp/classifier/infer.py @@ -5,6 +5,4 @@ def infer_tx_category(tx): """Will try to guess the category using different actions.""" print(f"Raw is: {tx.concept}\n") gmap_category = query_gmaps_category(tx.concept_clean) - if gmap_category: - print(f"Google Maps category is {gmap_category}") return gmap_category