def download_files_for_symbol(symbol, fromYear, toYear): if not os.path.exists(storage): logger.info("Creating %s directory" % (storage)) os.mkdir(storage) status = "" for year in range(fromYear, toYear+1): fileName = get_csv_filename(symbol, year) if not os.path.exists(fileName): logger.info("Downloading %s %d to %s" % (symbol, year, fileName)) try: yahoofinance.download_daily_bars(symbol, year, fileName) status += "1" except Exception as e: logger.error(str(e)) status += "0" else: status += "1" if status.find("1") == -1: logger.fatal("No data found for %s" % (symbol)) elif status.lstrip("0").find("0") != -1: logger.fatal("Some bars are missing for %s" % (symbol))
status = "" for year in range(fromYear, toYear+1): fileName = get_csv_filename(symbol, year) if not os.path.exists(fileName): logger.info("Downloading %s %d to %s" % (symbol, year, fileName)) try: yahoofinance.download_daily_bars(symbol, year, fileName) status += "1" except Exception, e: logger.error(str(e)) status += "0" else: status += "1" if status.find("1") == -1: logger.fatal("No data found for %s" % (symbol)) elif status.lstrip("0").find("0") != -1: logger.fatal("Some bars are missing for %s" % (symbol)) def download_files(symbolsFile, fromYear, toYear): for symbol in open(symbolsFile, "r"): symbol = symbol.strip() download_files_for_symbol(symbol, fromYear, toYear) def update_db_for_symbol(db, symbol, timezone, fromYear, toYear): feed = yahoofeed.Feed(timezone) feed.sanitizeBars(True) for year in range(fromYear, toYear+1): fileName = get_csv_filename(symbol, year) if os.path.exists(fileName): feed.addBarsFromCSV(symbol, fileName, timezone)
status = "" for year in range(fromYear, toYear + 1): fileName = get_csv_filename(symbol, year) if not os.path.exists(fileName): logger.info("Downloading %s %d to %s" % (symbol, year, fileName)) try: yahoofinance.download_daily_bars(symbol, year, fileName) status += "1" except Exception, e: logger.error(str(e)) status += "0" else: status += "1" if status.find("1") == -1: logger.fatal("No data found for %s" % (symbol)) elif status.lstrip("0").find("0") != -1: logger.fatal("Some bars are missing for %s" % (symbol)) def main(): fromYear = 2000 toYear = 2013 try: symbolsFile = os.path.join("..", "symbols", "merval.xml") callback = lambda stock: download_files_for_symbol( stock.getTicker(), fromYear, toYear) symbolsxml.parse(symbolsFile, callback, callback) except Exception, e: logger.error(str(e))