Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def download(account, fromto, output, ignore_pending, suppress_warnings, plaid_credentials):
client = open_client(plaid_credentials, suppress_warnings)
access_token = read_access_token(account['institution'])
account_name = account['name']
account_id = account['id']
response = client.Transactions.get(access_token,
fromto['start'], fromto['end'],
account_ids=[account_id])
txn_batch = len(response['transactions'])
txn_total = response['total_transactions']
txn_sofar = txn_batch
output_to_file = True if output['dir'] else False
output_file = '%s/%s' % (output['dir'], util.output_filename(account_name, fromto, output['format']))
output_handle = output_to_file and open(output_file, 'w') or sys.stdout
try:
w = transaction_writer.TransactionWriter.instance(output['format'], output_handle)
w.begin(account)
debug("txn cnt: %d, txn total: %d" % (txn_batch, txn_total))
while txn_batch > 0 and txn_batch <= txn_total:
for t in response['transactions']:
if ignore_pending and t['pending']:
info('skipping pending transaction for [%s: %s]' % (t['date'], t['name']))
continue
info('writing record for [%s: %s]' % (t['date'], t['name']))
debug('%s' % t)