How to use the plaid2qif.util.output_filename function in plaid2qif

To help you get started, we’ve selected a few plaid2qif examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ebridges / plaid2qif / plaid2qif / plaid2qif.py View on Github external
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)