Stock Historical Data
In my DB project I want to design a site for stock mining. First thing I did is writing a bot for downloading all stock historical data in Python. I really like Python it makes my life a lot easier and more effective. Unless I don’t feel I’m really live effectively!
Here is code:
import urllib2
f=open(‘cusip.txt’, ‘r’)
tickers = []
for line in f:
tickers.append(line.split(‘,’)[0])
for t in tickers:
# Open the URL
try:
rows=urllib2.urlopen(‘http://ichart.finance.yahoo.com/table.csv?’+\
’s=%s&d=09&e=05&f=2008&g=d&a=3&b=12&c=1997′%t +\
‘&ignore=.csv’).read()
t = open(t+’.csv’,'w’)
t.write(rows)
t.close()except IOError:
errors = [t]
errf = open(‘bad_trickers.txt’,'w’)
errf.write(str(errors))
errf.close()
f.close()
print errorsClick here to download!
