Organizing Earnings Data
import urllib2
###
import matplotlib
import numpy
###
def grabQuandl(ticker):
netIncomeAr = []
revAr = []
ROCAr = []
endLink = 'sort_order=asc'
endLink2 = 'sort_order=asc&auth_token=asdfasdfsagsvasd'
try:
netIncome = urllib2.urlopen('http://www.quandl.com/api/v1/datasets/OFDP/DMDRN_'+ticker+'_NET_INC.csv?&'+endLink2).read()
revenue = urllib2.urlopen('http://www.quandl.com/api/v1/datasets/OFDP/DMDRN_'+ticker+'_REV_LAST.csv?&'+endLink2).read()
ROC = urllib2.urlopen('http://www.quandl.com/api/v1/datasets/OFDP/DMDRN_'+ticker+'_ROC.csv?&'+endLink2).read()
####
splitNI = netIncome.split('\n')
print 'Net Income:'
for eachNI in splitNI[1:-1]:
print eachNI
netIncomeAr.append(eachNI)
print '___________'
splitRev = revenue.split('\n')
print 'Revenue:'
for eachRev in splitRev[1:-1]:
print eachRev
revAr.append(eachRev)
print '___________'
splitROC = ROC.split('\n')
print 'Return on Capital:'
for eachROC in splitROC[1:-1]:
print eachROC
ROCAr.append(eachROC)
####
except Exception, e:
print 'failed the main quandl loop for reason of',str(e)
grabQuandl('YHOO')
The next tutorial: