clean up typing a bit more
This commit is contained in:
@@ -18,7 +18,7 @@ class AmazonAccount:
|
||||
password: str
|
||||
|
||||
|
||||
def get_accounts(env: dict[str, str] = os.environ) -> list[AmazonAccount]:
|
||||
def get_accounts(env: os._Environ | dict[str, str] = os.environ) -> list[AmazonAccount]:
|
||||
accts = []
|
||||
for k, v in env.items():
|
||||
if k == 'AMAZON_EMAIL':
|
||||
|
||||
52
src/main.py
52
src/main.py
@@ -16,6 +16,29 @@ import ai
|
||||
import ynab_client
|
||||
|
||||
|
||||
@dataclass
|
||||
class Context:
|
||||
sync_days: int
|
||||
budget_id: str
|
||||
ynab_token: str
|
||||
amz_accts: list[tuple[str, str]]
|
||||
ynab_client: ynab_client.YnabClient
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
sync_days: int,
|
||||
budget_id: str | None = None,
|
||||
ynab_token: str | None = None,
|
||||
):
|
||||
self.sync_days = sync_days
|
||||
self.amazon_accts = amazon.get_accounts()
|
||||
self.ynab_client = ynab_client.YnabClient(
|
||||
budget_id=budget_id if budget_id else os.environ['YNAB_BUDGET_ID'],
|
||||
ynab_token=ynab_token if ynab_token else os.environ['YNAB_TOKEN'],
|
||||
sync_days=sync_days,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TxCategory:
|
||||
category_name: str | None
|
||||
@@ -31,7 +54,8 @@ def tx_date_diff(amz_tx: Transaction, ynab_tx: TransactionDetail):
|
||||
def is_matchable_ynab(tx: TransactionDetail) -> bool:
|
||||
return (
|
||||
# we only care about amazon transactions
|
||||
'amazon' in tx.payee_name.lower()
|
||||
tx.payee_name is not None
|
||||
and 'amazon' in tx.payee_name.lower()
|
||||
# don't categorize them if we already have, or if the user has manually approved
|
||||
and tx.flag_color != 'purple'
|
||||
and not tx.approved
|
||||
@@ -85,7 +109,8 @@ def get_tx_categories(
|
||||
details = item_details[item.title]
|
||||
by_category[details.category].append(item)
|
||||
|
||||
subtotal = sum(i.price for i in order.items)
|
||||
# we have already ensured that order details are fully populated, so i.price should not be None
|
||||
subtotal = sum(i.price for i in order.items) # type: ignore
|
||||
tx_categories = []
|
||||
for category_name, items in by_category.items():
|
||||
category_total = 0
|
||||
@@ -143,29 +168,6 @@ def build_tx_update(
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Context:
|
||||
sync_days: int
|
||||
budget_id: str
|
||||
ynab_token: str
|
||||
amz_accts: list[tuple[str, str]]
|
||||
ynab_client: ynab_client.YnabClient
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
sync_days: int,
|
||||
budget_id: str | None = None,
|
||||
ynab_token: str | None = None,
|
||||
):
|
||||
self.sync_days = sync_days
|
||||
self.amazon_accts = amazon.get_accounts()
|
||||
self.ynab_client = ynab_client.YnabClient(
|
||||
budget_id=budget_id if budget_id else os.environ['YNAB_BUDGET_ID'],
|
||||
ynab_token=ynab_token if ynab_token else os.environ['YNAB_TOKEN'],
|
||||
sync_days=sync_days,
|
||||
)
|
||||
|
||||
|
||||
def sync_account(ctx: Context, acct: AmazonAccount):
|
||||
print(f'Syncing transactions from Amazon account: {acct.email}')
|
||||
with amazon.Session(acct) as amz:
|
||||
|
||||
Reference in New Issue
Block a user