<jupyter_start><jupyter_text>Extracting open close and vol<jupyter_code>import time
# Contain day 1 data 
open_data_f = []
close_data_f = []
vol_data_f = []

# Contain next day data
open_data_c = []
close_data_c = []
vol_data_c = []

callcounter = 0

#loop through ticker and dates
for ticker,date in zip(df["Ticker"],df["realfiledDate"]):
    #combine the ticker with the url
    av_url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + str(ticker) + "&outputsize=full&apikey=<KEY>"
    #load up in json
    with urllib.request.urlopen(av_url) as url:
        data = json.loads(url.read().decode())
    #loop through the dates
    try:
        for i in data["Time Series (Daily)"]:
        #check if the date is inside the json file and extract and append
            if i == date:
                open_data_1 = data["Time Series (Daily)"][i]["1. open"]
                open_data_f.append(open_data_1)
                close_data_1 = data["Time Series (Daily)"][i]["4. close"]
                close_data_f.append(close_data_1)
                vol_data_1 = data["Time Series (Daily)"][i]["5. volume"]
                vol_data_f.append(vol_data_1)
                # next day data
                first_day = datetime.datetime.strptime(date, "%Y-%m-%d")
                next_day = first_day + datetime.timedelta(days=1)
                next_day_str = next_day.strftime("%Y-%m-%d")
                # extract and append
                open_data_2 = data["Time Series (Daily)"][next_day_str]["1. open"]
                open_data_c.append(open_data_2)
                close_data_2 = data["Time Series (Daily)"][next_day_str]["4. close"]
                close_data_c.append(close_data_2)
                vol_data_2 = data["Time Series (Daily)"][next_day_str]["5. volume"]
                vol_data_c.append(vol_data_2)
    except:
        no_text = "NA"
        open_data_f.append(no_text)
        close_data_f.append(no_text)
        vol_data_f.append(no_text)
        
        open_data_c.append(no_text)
        close_data_c.append(no_text)
        vol_data_c.append(no_text)
    
    if callcounter < 6:
        callcounter += 1
    else:
        time.sleep(61)
        callcounter = 0
        
    print("row done")

stock_value = {"open_first":open_data_f,
              "close_first":close_data_f,
              "vol_first":vol_data_f,
              "open_second":open_data_c,
              "close_second":close_data_c,
              "vol_second":vol_data_c}

df_stock_data = pd.DataFrame(stock_value)
df_stock_data.head(20)
print(len(open_data_c))
print(len(close_data_c))
print(len(vol_data_c))
print(len(open_data_f))
print(len(close_data_f))
print(len(vol_data_f))
len(df["Ticker"])
stock_value_1 = {"open_first":open_data_f,
              "close_first":close_data_f,
              "vol_first":vol_data_f}

stock_value_2 = {"open_second":open_data_c,
              "close_second":close_data_c,
              "vol_second":vol_data_c}

df_stock_1 = pd.DataFrame(stock_value_1)
df_stock_2 = pd.DataFrame(stock_value_2)

df_stock_1.to_csv("stock_values_first_day.csv")
df_stock_2.to_csv("stock_values_second_day.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11983601387574898, 'fraction_numerical': 0.011352885525070956, 'mean_word_length': 2.723004694835681, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '664750', 'license': 'MIT', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1112, 'n_words': 179, 'path': 'Edgar_extracting_api.ipynb', 'repo_name': 'Victork2267/Uplevel-Financial-Project', 'size': '3182'}