symbols = scrape_symbols() #dates we are dealing with to scrape data currentDate = datetime.now().date() fiveYearsAgo = datetime.now() - relativedelta(years=5) fiveYearsAgo = fiveYearsAgo.date() startDate = fiveYearsAgo.strftime('%Y-%m-%d') endDate = currentDate.strftime('%Y-%m-%d') #remove symbols that won't have 5 years worth of data for symbol in symbols: try: stock = Share(symbol) plusMonth = fiveYearsAgo + relativedelta(days=30) endDate2 = plusMonth.strftime('%Y-%m-%d') stock.get_historical_data(startDate, endDate2) except: symbols.remove(symbol) #print len(symbols) #pick 40 random stocks to scrape for 5 years #sample_size = 40 #sample_symbols = random.sample(symbols, sample_size) #data to scrape data = { 'Symbol': [], 'Date': [], 'Open': [], 'High': [],