def build_feed(instFeed, fromYear, toYear): feed = yahoofeed.Feed() for year in range(fromYear, toYear + 1): for symbol in instFeed: fileName = "%s-%d.csv" % (symbol, year) if not os.path.exists(fileName): print "Downloading %s %d" % (symbol, year) csv = yahoofinance.get_daily_csv(symbol, year) f = open(fileName, "w") f.write(csv) f.close() feed.addBarsFromCSV(symbol, fileName) return feed
def build_feed(instruments, fromYear, toYear): feed = yahoofeed.Feed() for year in range(fromYear, toYear+1): for symbol in instruments: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) if not os.path.exists(fileName): print "Downloading %s %d" % (symbol, year) csv = yahoofinance.get_daily_csv(symbol, year) f = open(fileName, "w") f.write(csv) f.close() feed.addBarsFromCSV(symbol, fileName) return feed
def download_bars(db, symbol, year, timezone): try: # Download bars. csvFile = tempfile.NamedTemporaryFile() csvFile.write(yahoofinance.get_daily_csv(symbol, year)) csvFile.flush() # Load them into a feed. feed = yahoofeed.Feed() feed.addBarsFromCSV(symbol, csvFile.name, timezone) # Put them in the db. db.addBarsFromFeed(feed) except Exception, e: logger.error("Error downloading %s bars for %s: %s" % (symbol, year, str(e)))