Last active
December 23, 2015 06:09
-
-
Save barvinograd/6592024 to your computer and use it in GitHub Desktop.
Yahoo! Historical Stock Prices Crawler. Downloads historical prices of stocks. Ticker lists is available from http://www.nasdaq.com/screening/company-list.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import datetime | |
from os.path import isfile, join | |
from os import getcwd | |
tFile = open("tickers.txt") | |
eYear = datetime.datetime.now().year | |
eMonth = datetime.datetime.now().month | |
eDay = datetime.datetime.now().day | |
for ticker in tFile: | |
ticker = ticker.strip() | |
if (isfile(join(getcwd(), ticker + ".csv"))): | |
continue | |
print join(getcwd(), ticker + ".csv") | |
url = "http://ichart.finance.yahoo.com/table.csv?s={0}&d={1}&e={2}&f={3}&g=d&a=1&b=1&c=1900&ignore=.csv".format(ticker, eMonth, eYear, eDay) | |
print "downloading data for ", ticker, "...", | |
try: | |
response = urllib2.urlopen(url) | |
data = response.read() | |
with open(ticker + ".csv", "w") as tData: | |
tData.write(data) | |
print " done." | |
except Exception as ex: | |
print " error occurred. " , ex, "." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment