Example #1
0
class GoogleDAM(BaseDAM):
    ''' Google DAO '''

    def __init__(self):
        ''' constructor '''
        super(GoogleDAM, self).__init__()
        self.__gf = GoogleFinance()

    def readQuotes(self, start, end):
        ''' read quotes from google Financial'''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return []

        return self.__gf.getQuotes(self.symbol, start, end)

    def readTicks(self, start, end):
        ''' read ticks from google Financial'''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return []

        return self.__gf.getTicks(self.symbol, start, end)

    def readFundamental(self):
        ''' read fundamental '''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return {}

        return self.__gf.getFinancials(self.symbol)
class GoogleDAM(BaseDAM):
    ''' Google DAO '''
    def __init__(self):
        ''' constructor '''
        super(GoogleDAM, self).__init__()
        self.__gf = GoogleFinance()

    def readQuotes(self, start, end):
        ''' read quotes from google Financial'''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return []

        return self.__gf.getQuotes(self.symbol, start, end)

    def readTicks(self, start, end):
        ''' read ticks from google Financial'''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return []

        return self.__gf.getTicks(self.symbol, start, end)

    def readFundamental(self):
        ''' read fundamental '''
        if self.symbol is None:
            LOG.debug('Symbol is None')
            return {}

        return self.__gf.getFinancials(self.symbol)
Example #3
0
class UFGoogleDataSerializer(object):
    def __init__(self, symbol):
        self.symbol = symbol

    def fetch(self):
        self.financials = GoogleFinance().getFinancials(self.symbol)

    def serialize_financials(self):
        self.result = {}
        h = HTMLParser.HTMLParser()
        for item_name, values in self.financials.iteritems():
            item_name = h.unescape(item_name)
            statement_type = GoogleLedgerItem.get_statement_type(item_name)
            for date, value in values.iteritems():
                if value:
                    d = GoogleDateParser(date)
                    self._store_result(d, statement_type, item_name, value)
        print self.result

    def _store_result(self, date, statement_type, item_name,
            value):
        day = date.getDay()
        period = date.getPeriod()
        if day not in self.result:
            self.result[day] = {}
        if statement_type not in self.result[day]:
            self.result[day][statement_type] = {}
        if period not in self.result[day][statement_type]:
            self.result[day][statement_type][period] = {}
        assert item_name not in self.result[day][statement_type][period]
        self.result[day][statement_type][period][item_name] = value
Example #4
0
    def getStockFinancials(self, writeOutput=False):
        ''' get stock financials '''
        with open(self.__stockList) as inFile:
            stockFinancials = {}

            for stockName in inFile.readlines():
                try:
                    stockName = stockName.strip()
                    googleFinance = GoogleFinance()
                    financials = googleFinance.getFinancials(stockName)
                    print "Processed %s" % stockName
                    stockFinancials[stockName] = financials
                except StandardError as excp:
                    print '%s' % excp

            if writeOutput:
                with open(self.__outputFile, 'w') as outFile:
                    outFile.write(json.dumps(stockFinancials))

            return stockFinancials

        return {}
Example #5
0
    def getStockFinancials(self, writeOutput=False):
        ''' get stock financials '''
        with open(self.__stockList) as inFile:
            stockFinancials = {}

            for stockName in inFile.readlines():
                try:
                    stockName = stockName.strip()
                    googleFinance = GoogleFinance()
                    financials = googleFinance.getFinancials(stockName)
                    print "Processed %s" % stockName
                    stockFinancials[stockName] = financials
                except StandardError as excp:
                    print '%s' % excp

            if writeOutput:
                with open(self.__outputFile, 'w') as outFile:
                    outFile.write(json.dumps(stockFinancials))

            return stockFinancials

        return {}
 def testGetAll(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getAll('EBAY')
     print(data)
     self.assertNotEqual(0, len(data))
 def testGetQuotes(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getQuotes('NASDAQ:EBAY', '20110101', '20110110')
     assert len(data)
 def testGetTicks(self):
     googleFinance = GoogleFinance()
     ret = googleFinance.getTicks('EBAY', start = '20110101', end = '20110110')
     print(ret)
 def testGetFinancials(self):
     googleFinance = GoogleFinance()
     #ret = googleFinance.getFinancials('NASDAQ:EBAY', ['Net Income', 'Total Revenue', 'Diluted Normalized EPS', 'Total Common Shares Outstanding'], False)
     ret = googleFinance.getFinancials('NASDAQ:EBAY')
     print(ret)
 def testGetAll(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getAll('EBAY')
     print(data)
     self.assertNotEqual(0, len(data))
 def testGetFinancials(self):
     googleFinance = GoogleFinance()
     #ret = googleFinance.getFinancials('NASDAQ:EBAY', ['Net Income', 'Total Revenue', 'Diluted Normalized EPS', 'Total Common Shares Outstanding'], False)
     ret = googleFinance.getFinancials('NASDAQ:EBAY')
     print(ret)
Example #12
0
 def fetch(self):
     self.financials = GoogleFinance().getFinancials(self.symbol)
Example #13
0
 def __init__(self):
     ''' constructor '''
     super(GoogleDAM, self).__init__()
     self.__gf = GoogleFinance()
 def testGetQuotes(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getQuotes('NASDAQ:EBAY', '20131101', None)
     print[str(q) for q in data]
     assert len(data)
 def testGetQuotes(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getQuotes('NASDAQ:EBAY', '20110101', '20110110')
     assert len(data)
 def testGetAll_badSymbol(self):
     googleFinance = GoogleFinance()
     self.assertRaises(UfException, googleFinance.getAll, 'fasfdsdfasf')
 def testGetQuotes_badSymbol(self):
     googleFinance = GoogleFinance()
     self.assertRaises(UfException, googleFinance.getQuotes, *['AFSDFASDFASDFS', '20110101', '20110110'])
 def __init__(self):
     ''' constructor '''
     super(GoogleDAM, self).__init__()
     self.__gf = GoogleFinance()
 def testGetTicks(self):
     googleFinance = GoogleFinance()
     ret = googleFinance.getTicks('EBAY', start = '20110101', end = '20110110')
     print(ret)
 def testGetQuotes(self):
     googleFinance = GoogleFinance()
     data = googleFinance.getQuotes('NASDAQ:EBAY', '20131101', None)
     print [str(q) for q in data]