Skip to content

Commit

Permalink
🐛 cli imports
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin authored Dec 25, 2023
1 parent 9602a57 commit db22a16
Showing 2 changed files with 62 additions and 62 deletions.
53 changes: 50 additions & 3 deletions lunchable/_cli.py
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@
from lunchable import LunchMoney
from lunchable._config.logging_config import set_up_logging
from lunchable.models import LunchableModel
from lunchable.plugins.primelunch.primelunch import run_primelunch
from lunchable.plugins.pushlunch import PushLunch

logger = logging.getLogger(__name__)

@@ -381,6 +379,8 @@ def notify(continuous: bool, interval: int, user_key: str) -> None:
"""
Send a Notification for each Uncleared Transaction
"""
from lunchable.plugins.pushlunch import PushLunch

push = PushLunch(user_key=user_key)
if interval is not None:
interval = int(interval)
@@ -430,4 +430,51 @@ def primelunch() -> None:
"""


primelunch.add_command(run_primelunch)
@primelunch.command("run")
@click.option(
"-f",
"--file",
"csv_file",
type=click.Path(exists=True, resolve_path=True),
help="File Path of the Amazon Export",
required=True,
)
@click.option(
"-w",
"--window",
"window",
type=click.INT,
help="Allowable time window between Amazon transaction date and "
"credit card transaction date",
default=7,
)
@click.option(
"-a",
"--all",
"update_all",
is_flag=True,
type=click.BOOL,
help="Whether to skip the confirmation step and simply update all matched "
"transactions",
default=False,
)
@click.option(
"-t",
"--token",
"access_token",
type=click.STRING,
help="LunchMoney Access Token - defaults to the LUNCHMONEY_ACCESS_TOKEN environment variable",
envvar="LUNCHMONEY_ACCESS_TOKEN",
)
def run_primelunch(
csv_file: str, window: int, update_all: bool, access_token: str
) -> None:
"""
Run the PrimeLunch Update Process
"""
from lunchable.plugins.primelunch.primelunch import PrimeLunch

primelunch = PrimeLunch(
file_path=csv_file, time_window=window, access_token=access_token
)
primelunch.process_transactions(confirm=not update_all)
71 changes: 12 additions & 59 deletions lunchable/plugins/primelunch/primelunch.py
Original file line number Diff line number Diff line change
@@ -11,21 +11,27 @@
import pathlib
from typing import Any, Optional, Union

import click
import numpy as np
import pandas as pd
from numpy import datetime64
from rich import print, table
from rich.prompt import Confirm

from lunchable._config.logging_config import set_up_logging
from lunchable._version import __application__
from lunchable.exceptions import LunchMoneyImportError
from lunchable.models import (
CategoriesObject,
TransactionObject,
TransactionUpdateObject,
UserObject,
)
from lunchable.plugins.base.pandas_app import LunchablePandasApp

try:
import numpy as np
import pandas as pd
from numpy import datetime64

from lunchable.plugins.base.pandas_app import LunchablePandasApp
except ImportError as e:
msg = f'PrimeLunch requires the `primelunch` extras to be installed: `pip install "{__application__}[primelunch]"`'
raise LunchMoneyImportError(msg) from e

logger = logging.getLogger(__name__)

@@ -391,56 +397,3 @@ def format_currency(amount: float) -> str:
else:
float_string = f"[bold green]$ {float(amount):,.2f}[/bold green]"
return float_string


@click.command("run")
@click.option(
"-f",
"--file",
"csv_file",
type=click.Path(exists=True, resolve_path=True),
help="File Path of the Amazon Export",
required=True,
)
@click.option(
"-w",
"--window",
"window",
type=click.INT,
help="Allowable time window between Amazon transaction date and "
"credit card transaction date",
default=7,
)
@click.option(
"-a",
"--all",
"update_all",
is_flag=True,
type=click.BOOL,
help="Whether to skip the confirmation step and simply update all matched "
"transactions",
default=False,
)
@click.option(
"-t",
"--token",
"access_token",
type=click.STRING,
help="LunchMoney Access Token - defaults to the LUNCHMONEY_ACCESS_TOKEN environment variable",
envvar="LUNCHMONEY_ACCESS_TOKEN",
)
def run_primelunch(
csv_file: str, window: int, update_all: bool, access_token: str
) -> None:
"""
Run the PrimeLunch Update Process
"""
primelunch = PrimeLunch(
file_path=csv_file, time_window=window, access_token=access_token
)
primelunch.process_transactions(confirm=not update_all)


if __name__ == "__main__":
set_up_logging(log_level=logging.INFO)
run_primelunch()

0 comments on commit db22a16

Please sign in to comment.