class HistoricalDataFeeder(BaseModule):
    '''
    feeder that get stock data from Yahoo Finance
    '''
    def __init__(self):
        ''' Constructor '''
        super(HistoricalDataFeeder, self).__init__()
        self.__yahooFinance = YahooFinance()

    def execute(self, input):
        ''' preparing data'''
        super(HistoricalDataFeeder, self).execute(input)
        return {'history stock': self.__yahooFinance.get_historical_prices(input, '1990-01-01', date.today())}
    def __buildExl(self, stock, workbook):
        ''' get one stock historical data and store it '''
        try:
            ws = workbook.add_sheet(stock)

            #get data
            yahooFinance = YahooFinance()
            allData = yahooFinance.get_historical_prices(stock, self.__startDate, self.__endDate)
            for col, field in enumerate(['date', 'open', 'high', 'low', 'close', 'volume', 'adjClose']):
                ws.write(0, col, field)

            for row, data in enumerate(allData):
                for col, field in enumerate(['date', 'open', 'high', 'low', 'close', 'volume', 'adjClose']):
                    ws.write(row+1, col, getattr(data, field) )

        except ufException as excp:
            raise excp
        except Exception:
            raise ufException(Errors.UNKNOWN_ERROR, "historicalStorage.__buildExl got unknown error  %s"
                              % traceback.print_exc())
 def testGetHistoricalPrices(self):
     yahooFinance = YahooFinance()
     data = yahooFinance.get_historical_prices('^STI', '20110101', '20110110')
     assert len(data)