diff --git a/xactfetch.py b/xactfetch.py index 0ed529c..be03e88 100644 --- a/xactfetch.py +++ b/xactfetch.py @@ -421,21 +421,29 @@ class CommerceBank: self, from_date: datetime.date, to_date: datetime.date ) -> Path: log.info('Downloading transactions from %s to %s', from_date, to_date) - idx = self.page.url.rstrip('/').split('/')[-1] - href = ( - f'Download.ashx?Index={idx}' - f'&From={from_date}&To={to_date}' - f'&Type=csv' - '&DurationOfMonths=6' - ) - log.debug('Navigating to %s', href) + datefmt = '%m/%d/%Y' + self.page.get_by_role('link', name='Download Transactions').click() + self.page.wait_for_timeout(random.randint(750, 1250)) + modal = self.page.locator('#download-transactions') + input_from = modal.locator('input[data-qaid=fromDate]') + input_from.click() + self.page.keyboard.press('Control+A') + self.page.keyboard.press('Delete') + self.page.keyboard.type(from_date.strftime(datefmt)) + input_to = modal.locator('input[data-qaid=toDate]') + input_to.click() + self.page.keyboard.press('Control+A') + self.page.keyboard.press('Delete') + self.page.keyboard.type(to_date.strftime(datefmt)) + modal.get_by_role('button', name='Select Type').click() + self.page.get_by_text('Comma Separated').click() with self.page.expect_download() as di: - self.page.evaluate(f'window.location.href = "{href}";') + self.page.get_by_role('button', name='Download').click() log.debug('Waiting for download to complete') - self.page.wait_for_timeout(random.randint(1000, 3000)) path = di.value.path() assert path log.info('Downloaded transactions to %s', path) + modal.get_by_label('Close').click() return path def firefly_import(self, csv: Path, account: int, token: str) -> None: