From 60916664710213db8fa9d08cb72a4cd7b419a06f Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 2 Dec 2023 12:46:50 -0600 Subject: [PATCH] Check latest transaction before logging in If the latest transaction was recent enough to skip importing transactions, we don't even need to log in to the bank websites. Thus, we should delay the login step until after we've checked this. --- xactfetch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xactfetch.py b/xactfetch.py index 5c70326..271db71 100644 --- a/xactfetch.py +++ b/xactfetch.py @@ -206,7 +206,6 @@ def download_chase( page: Page, end_date: datetime.date, token: str, importer: FireflyImporter ) -> bool: with Chase(page) as c, ntfyerror('Chase', page) as r: - c.login() key = ACCOUNTS['chase'] try: start_date = get_last_transaction_date(key, token) @@ -222,6 +221,7 @@ def download_chase( start_date, ) return True + c.login() csv = c.download_transactions(start_date, end_date) log.info('Importing transactions from Chase into Firefly III') c.firefly_import(csv, key, importer) @@ -237,7 +237,6 @@ def download_commerce( log.info('Downloading transaction lists from Commerce Bank') csvs = [] with CommerceBank(page) as c, ntfyerror('Commerce Bank', page) as r: - c.login() for name, key in ACCOUNTS['commerce'].items(): try: start_date = get_last_transaction_date(key, token) @@ -260,6 +259,7 @@ def download_commerce( start_date, name, ) + c.login() c.open_account(name) csvs.append((key, c.download_transactions(start_date, end_date))) log.info('Importing transactions from Commerce Bank into Firefly III') @@ -382,6 +382,8 @@ class CommerceBank: self.logout() def login(self) -> None: + if self._logged_in: + return log.debug('Navigating to %s', self.URL) self.page.goto(self.URL) password = rbw_get(self.vault_item, self.vault_folder, self.username) @@ -567,6 +569,8 @@ class Chase: log.info('Successfully saved cookies to %s', self.saved_cookies) def login(self) -> None: + if self._logged_in: + return log.debug('Navigating to %s', self.URL) self.page.goto(self.URL) self.page.wait_for_load_state()