def ensure_treasury_data(bm_symbol, first_date, last_date, now):
 (loader_module, filename, source) = INDEX_MAPPING.get(bm_symbol, INDEX_MAPPING['^GSPC'])
 first_date = max(first_date, loader_module.earliest_possible_date())
 path = get_data_filepath(filename)
 if os.path.exists(path):
  try:
   data = pd.DataFrame.from_csv(path).tz_localize('UTC')
   if has_data_for_dates(data, first_date, last_date):
    return data
   last_download_time = last_modified_time(path)
   if ((now - last_download_time) <= ONE_HOUR):
    logger.warn(('Refusing to download new treasury data because a download succeeded at %s.' % last_download_time))
    return data
  except (OSError, IOError, ValueError) as e:
   logger.info('Loading data for {path} failed with error [{error}].'.format(path=path, error=e))
 try:
  data = loader_module.get_treasury_data(first_date, last_date)
  data.to_csv(path)
 except (OSError, IOError, HTTPError):
  logger.exception('failed to cache treasury data')
 if (not has_data_for_dates(data, first_date, last_date)):
  logger.warn("Still don't have expected data after redownload!")
 return data

def ensure_treasury_data ( bm_symbol , first_date , last_date , now ) : ( loader_module , filename , source ) = INDEX_MAPPING . get ( bm_symbol , INDEX_MAPPING [ '^GSPC' ] ) first_date = max ( first_date , loader_module . earliest_possible_date ( ) ) path = get_data_filepath ( filename ) if os . path . exists ( path ) : try : data = pd . DataFrame . from_csv ( path ) . tz_localize ( 'UTC' ) if has_data_for_dates ( data , first_date , last_date ) : return data last_download_time = last_modified_time ( path ) if ( ( now - last_download_time ) <= ONE_HOUR ) : logger . warn ( ( 'Refusing to download new treasury data because a download succeeded at %s.' % last_download_time ) ) return data except ( OSError , IOError , ValueError ) as e : logger . info ( 'Loading data for {path} failed with error [{error}].' . format ( path = path , error = e ) ) try : data = loader_module . get_treasury_data ( first_date , last_date ) data . to_csv ( path ) except ( OSError , IOError , HTTPError ) : logger . exception ( 'failed to cache treasury data' ) if ( not has_data_for_dates ( data , first_date , last_date ) ) : logger . warn ( "Still don't have expected data after redownload!" ) return data
ensure we have treasury data from treasury module associated with bm_symbol .