def _do_account_dir(self, acct_id, path):
"""
Handle all OFX statements in a per-account directory.
:param acct_id: account database ID
:type acct_id: int
:param path: absolute path to per-account directory
:type path: str
"""
logger.debug('Doing account %d directory (%s)', acct_id, path)
files = {}
for f in os.listdir(path):
p = os.path.join(path, f)
if not os.path.isfile(p):
continue
extension = p.split('.')[-1].lower()
if extension not in ['ofx', 'qfx']:
continue
files[p] = os.path.getmtime(p)
logger.debug('Found %d files for account %d', len(files), acct_id)
# run through the files, oldest to newest
success = 0
already = 0
for p in sorted(files, key=files.get):
try:
self._do_one_file(acct_id, p)
success += 1
except DuplicateFileException:
already += 1
logger.warning('OFX is already parsed for account; skipping')
except (InvalidRequestError, IntegrityError, TypeError):
raise
except Exception:
logger.error('Exception parsing and inserting file %s',
p, exc_info=True)
logger.info('Successfully parsed and inserted %d of %d files for '
'account %d; %d files already in DB', success, len(files),
acct_id, already)
评论列表
文章目录