def main(opts):

    """
    This function handles the execution of the script
    opts:  Namespace(delimeter=',', header=True, input_csv_filepath='somefilepath', output='Bond_Valuations.cvs', v=False, valuation_date='08/2015')
    """

    if opts.v:
        logging.basicConfig(level=logging.INFO)

    bonds_list = csv_parser.load_from_csv(filepath = opts.input_csv_filepath, header = opts.header, delim = opts.delimeter)

    f = open(opts.output, 'a')

    logging.info("Opening output file:  %s", opts.output)

    writer = csv.writer(f)

    headers = ['Number', 'SerialNum', 'ValuationDate', 'SeriesType', 'Denomination', 'IssueDate', 'NextAccrualDate', 'FinalMaturity', 'IssuePrice', 'TotalInterest', 'InterestRate', 'YtdInterest', 'Value', 'CAGR']

    for n, bond in enumerate(bonds_list, 1):
        try:
            valuation_results = td.parse_url(params = bond, valuation_date = opts.valuation_date)


            if n == 1 and f.tell() == 0:
                writer.writerow(headers)

            output = [n] + valuation_results

            logging.info('Writing to file:  %s', output)
            writer.writerow(output)

        except Exception as e:
            logging.warning("Issue writing row: %s", n, bond)
            logging.warning("Exception: %s", e)
            raise

    f.close()
    logging.info("Completed output to file: %s", opts.output)
 def test_of_loading_multi(self):
     file_path = os.getcwd() + "/test/" + 'test_data.csv'
     self.assertEqual(csv_parser.load_from_csv(file_path, header = True), [{'Series': 'EE', 'SerialNumber': 'C777535063EE', 'IssueDate': '08/1989', 'Denomination': '100'}, {'Series': 'EE', 'SerialNumber': 'R114463707EE', 'IssueDate': '08/1994', 'Denomination': '200'}])
 def test_of_loading_single(self):
     file_path = os.getcwd() + "/test/" + 'test_one.csv'
     self.assertEqual(csv_parser.load_from_csv(file_path, header = True), [{'Series': 'EE', 'SerialNumber': 'R11111111', 'IssueDate': '12/2222', 'Denomination': '4000'}])