24 lines
No EOL
864 B
Python
24 lines
No EOL
864 B
Python
import os
|
|
import pandas as pd
|
|
import numpy as np
|
|
from scraper.top100_extractor import programming_crime_list
|
|
from typing import Optional
|
|
|
|
DF_HIST_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..', 'Elaborated_Data', 'price_history_data.csv')
|
|
DF_HIST: Optional[pd.DataFrame] = None
|
|
|
|
|
|
def lazy_load_history():
|
|
global DF_HIST
|
|
if DF_HIST is None:
|
|
DF_HIST = pd.read_csv(DF_HIST_PATH, index_col=0)
|
|
|
|
|
|
def get_closing_price_hist(tickers: list[str]) -> list[dict]:
|
|
lazy_load_history()
|
|
ticker_series = pd.Series(tickers)
|
|
df = DF_HIST.loc[DF_HIST.symbol.isin(ticker_series), :] \
|
|
.rename(columns={"Closing Price": "price", "symbol": "ticker"}) \
|
|
.reset_index(drop=True)
|
|
df = df.pivot(index='date', columns='ticker', values='price').reset_index(drop=False)
|
|
return df.replace({ np.nan: None }).to_dict('records') |