def list_accounts_from_file()

in source/get-accounts-info-lambda.py [0:0]


def list_accounts_from_file():
    logger.info("Extracting Accounts via File Input:" + os.environ['BUCKET_NAME'] +','+os.environ['OBJECT_NAME'])
    accounts = {}
    accounts["accounts"] = []
    file_name = '/tmp/accounts.csv' 
    s3.download_file(os.environ['BUCKET_NAME'], os.environ['OBJECT_NAME'], 
        file_name)    
    with open(file_name) as csvfile:
        readCSV = csv.reader(csvfile, delimiter=',')
        x = 0
        # keep track of the positions, since this is a user defined file
        accountIdPos = 0
        accountNamePos = 0
        accountEmailPos = 0
        todaysDate = datetime.datetime.utcnow().strftime("%m-%d-%Y")
        todaysDateTime = datetime.datetime.utcnow().strftime('%Y-%m-%d %T')
        for row in readCSV:
            if len(row) == 3:
                # read in the headers
                if x == 0:
                    for y in range(len(row)):
                        if row[y].lower() == 'accountid':
                            accountIdPos = y
                        if row[y].lower() == 'accountname':
                            accountNamePos = y
                        if row[y].lower() == 'accountemail':
                            accountEmailPos = y
                else:
                    accounts["accounts"].append({"AccountId": row[accountIdPos].strip(), 
                                     "AccountName": row[accountNamePos].strip(), 
                                     "AccountEmail": row[accountEmailPos].strip(),
                                     "Date": todaysDate,
                                     "DateTime": todaysDateTime})
                    logger.info(sanitize_json({"AccountId": row[accountIdPos].strip(), 
                                     "AccountName": row[accountNamePos].strip(), 
                                     "AccountEmail": row[accountEmailPos].strip(),
                                     "Date": todaysDate,
                                     "DateTime": todaysDateTime}))
            else:
                logger.error("Input needs to have 3 fields: AccountId," +
                    "AccountName and AccountEmail")
                raise Exception("Insufficient fields in input file")
            x = x + 1
    return accounts