commerce: Use modal form to download CSV
The Commerce Bank website no longer allows navigating directly to `Download.ashx`; doing so just returns a generic "we're sorry" error. They appear to have added some CSRF protection or something that makes this not work. As a result, we have to go fill out the form on the *Download Transactions* modal dialog in order to get the download to work correctly.master
parent
3b432fc7d6
commit
805aa40e20
28
xactfetch.py
28
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:
|
||||
|
|
Loading…
Reference in New Issue