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 errors

Click here to download!

blog comments powered by Disqus

Search

Blogroll

Me Where Else?

Python

My micro log

digvan: RT @jeanineAKAj9: RT @effie313: RT @jfavreau: : “Love all, trust a few, do wrong to none” ~William Shakespeare #quote
17 hours ago
digvan: RT @voodootikigod: So facebook is becoming foursquare, iTunes is becoming facebook, and twitter is stable during a keynote. The future is nao.
2 days ago
digvan: RT @davidebbo: My machine has 67 instances of GoogleUpdate.exe running right now. It's nice to stay up to date!
1 week ago
digvan: RT @phil_nash: Welcome to the new decade: Java is a restricted platform, Google is evil, Apple is a monopoly and Microsoft are the underdogs
3 weeks ago