from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
from matplotlib.pyplot import figure
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
import requests
from copy import deepcopy
import pandas as pd
import sched, time
from pprint import pprint

s = sched.scheduler(time.time, time.sleep)

pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

res = requests.get("https://finance.yahoo.com/most-active")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0] 
df = pd.read_html(str(table))[0]
df['Volume_M'] = df.Volume.str.replace('M','')

ls = list(df['Symbol'].head(5))
lns = list(df['Name'].head(5))

# Alpha Vantage

# Your key here
key = '0CWSKG1FMCJU50OW'

# Chose your output format, or default to JSON (python dict)
ts = TimeSeries(key, output_format='pandas')
ti = TechIndicators(key)

# Get the data, returns a tuple
datas = ['one_data', 'two_data', 'three_data', 'four_data', 'five_data']
mdatas = ['one_meta_data', 'two_meta_data', 'three_meta_data', 'four_meta_data', 'five_meta_data']

s = sched.scheduler(time.time, time.sleep)

dfn = {}
def print_data(sc):
    for l, n, data, mdata in zip(ls, lns, datas, mdatas):
        data, mdata = ts.get_intraday(l, interval='1min', outputsize='full')
        s.enter(20, 1, print_data, (sc,))
        print(n)
        pprint(data['4. close'].head(1))
        dfn[n] = data['4. close'].head(1)
        print('\n')
        time.sleep(10)
s.enter(20, 1, print_data, (s,))
s.run() 