Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/ficamp/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
from collections import defaultdict
from decimal import Decimal

import questionary
from dotenv import load_dotenv
Expand Down Expand Up @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call the command "sink" with help: "send or store the results to the chosen sink" or something like that

categorize_parser.set_defaults(func=sync)

args = parser.parse_args()

return args
Expand Down Expand Up @@ -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:
Expand All @@ -138,13 +143,25 @@ def categorize(engine):
print("Session interrupted. Closing.")


def sync(args, engine):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also find "sync" a bit confusing for this functionality. I would go for something more in the direction of "print-summary".
So that can later be the 1st step in exporting to a sink or a making a true synchronization.

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")

Expand Down
Loading