Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ofxclient/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def client_args_for_bank(bank_info, ofx_version):
# Discover needs no User-Agent and no Accept headers
client_args['user_agent'] = False
client_args['accept'] = False
# Discover limits request rates
client_args['delay'] = '2'
if 'www.accountonline.com' in bank_info['url']:
# Citi needs no User-Agent header
client_args['user_agent'] = False
Expand Down
14 changes: 12 additions & 2 deletions ofxclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DEFAULT_OFX_VERSION = '102'
DEFAULT_USER_AGENT = 'httpclient'
DEFAULT_ACCEPT = '*/*, application/x-ofx'
DEFAULT_DELAY = '0'

LINE_ENDING = "\r\n"

Expand Down Expand Up @@ -48,6 +49,9 @@ class Client:
:param accept: Value to send for Accept HTTP header. Leave as
None to send default. Set to False to not send User-Agent header.
:type accept: str, None or False
:param delay: A number in seconds to delay after posting the request
Some institution may limit request rates
:type delay: str, None or False
"""

def __init__(
Expand All @@ -58,7 +62,8 @@ def __init__(
app_version=DEFAULT_APP_VERSION,
ofx_version=DEFAULT_OFX_VERSION,
user_agent=DEFAULT_USER_AGENT,
accept=DEFAULT_ACCEPT
accept=DEFAULT_ACCEPT,
delay=DEFAULT_DELAY
):
self.institution = institution
self.id = id
Expand All @@ -67,14 +72,16 @@ def __init__(
self.ofx_version = ofx_version
self.user_agent = user_agent
self.accept = accept
self.delay = delay
# used when serializing Institutions
self._init_args = {
'id': self.id,
'app_id': self.app_id,
'app_version': self.app_version,
'ofx_version': self.ofx_version,
'user_agent': self.user_agent,
'accept': self.accept
'accept': self.accept,
'delay': self.delay
}
self.cookie = 3

Expand Down Expand Up @@ -185,6 +192,9 @@ def _do_post(self, query, extra_headers=[]):
logging.debug('Headers: %s', res.getheaders())
logging.debug(response)
res.close()
if self.delay and int(self.delay):
logging.debug('Delay for %d seconds', self.delay)
time.sleep(int(self.delay))
return res, response

def next_cookie(self):
Expand Down