Skip to content

Commit

Permalink
Add dry-run optional argument to upload command
Browse files Browse the repository at this point in the history
  • Loading branch information
axeoman committed Aug 25, 2023
1 parent d5edbde commit 5fd7574
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ynab_sync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
get_ynab_budget,
get_ynab_budgets,
prepare_ynab_transactions,
print_upload_dry_run,
upload_to_ynab,
)

Expand All @@ -52,6 +53,7 @@ def upload(
gocardless_secret_id: str = os.getenv(ENV_GOCARDLESS_SECRET_ID, ""),
gocardless_secret_key: str = os.getenv(ENV_GOCARDLESS_SECRET_KEY, ""),
gocardless_account_id: str = os.getenv(ENV_GOCARDLESS_ACCOUNT_ID, ""),
dry_run: bool = False,
):
log = logging.getLogger("cli.upload")
# TODO: Get this from appeal?
Expand Down Expand Up @@ -96,6 +98,10 @@ def upload(
ynab_account_id=UUID(ynab_account_id),
)

if dry_run:
print_upload_dry_run(ynab_transactions)
return

upload_to_ynab(transactions=ynab_transactions, token=ynab_token, budget_id=UUID(ynab_budget_id))


Expand Down
19 changes: 19 additions & 0 deletions ynab_sync/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import UUID

from requests import HTTPError
from tabulate import tabulate

from ynab_sync.gocardless.models import (
GoCardlessBankAccountData,
Expand Down Expand Up @@ -122,3 +123,21 @@ def create_gocardless_requisition(
def get_gocardless_requisition(secret_id: str, secret_key: str, requisition_id: str) -> GoCardlessRequisition:
gocardless_api = GoCardLessAPI(secret_id=secret_id, secret_key=secret_key)
return gocardless_api.get_requisition(requisition_id=requisition_id)


def print_upload_dry_run(ynab_transations: YNABTransactions) -> None:
print("\nThis transactions have been returned by GoCardless API:\n")
table = tabulate(
[
(
transaction.date,
transaction.payee_name.replace("\n", " "),
transaction.memo.replace("\n", " "),
transaction.amount,
)
for transaction in ynab_transations.transactions
],
headers=["DATE", "PAYEE_NAME", "MEMO", "AMOUNT"],
tablefmt="github",
)
print(table)

0 comments on commit 5fd7574

Please sign in to comment.