mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-29 04:32:43 +00:00
* few changes * import fix * missed removing test config * column order fix * import fix * removed df2img add new deps * req * update readme * add dep for image export, fix * get rid of yahoo-fin, add image export lib * import issues in some machines fix * images dir fix * init fix * fix? * test * test * Fixed text handling Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: DjangoServer <colin99delahunty@gmail.com>
76 lines
2.0 KiB
Python
Executable File
76 lines
2.0 KiB
Python
Executable File
import logging
|
|
|
|
import pandas as pd
|
|
|
|
from bots import imps
|
|
from gamestonk_terminal.decorators import log_start_end
|
|
from gamestonk_terminal.economy import wsj_model
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def overview_command():
|
|
"""Market data overview [Wall St. Journal]"""
|
|
# Debug user input
|
|
if imps.DEBUG:
|
|
logger.debug("econ-overview")
|
|
|
|
# Retrieve data
|
|
df = wsj_model.market_overview()
|
|
|
|
# Check for argument
|
|
if df.empty:
|
|
raise Exception("No available data found")
|
|
|
|
df["Last Price"] = pd.to_numeric(df["Price"].astype(float))
|
|
df["Change"] = pd.to_numeric(df["Chg"].astype(float))
|
|
df["%Chg"] = pd.to_numeric(df["%Chg"].astype(float))
|
|
|
|
# Debug user output
|
|
if imps.DEBUG:
|
|
logger.debug(df.to_string())
|
|
|
|
formats = {
|
|
"Last Price": "${:.2f}",
|
|
"Change": "${:.2f}",
|
|
"%Chg": "<b>{:.2f}%</b>",
|
|
}
|
|
for col, value in formats.items():
|
|
df[col] = df[col].map(lambda x: value.format(x)) # pylint: disable=W0640
|
|
|
|
df["Change"] = df.apply(lambda x: f"{x['Change']} (<b>{x['%Chg']}</b>)", axis=1)
|
|
|
|
df = df.fillna("")
|
|
df.set_index(" ", inplace=True)
|
|
|
|
font_color = ["white"] * 2 + [
|
|
["#e4003a" if boolv else "#00ACFF" for boolv in df["Change"].str.contains("-")]
|
|
]
|
|
|
|
df = df.drop(columns=["Price", "Chg", "%Chg"])
|
|
fig = imps.plot_df(
|
|
df,
|
|
fig_size=(620, (40 + (40 * len(df.index)))),
|
|
col_width=[4, 2.4, 3],
|
|
tbl_header=imps.PLT_TBL_HEADER,
|
|
tbl_cells=imps.PLT_TBL_CELLS,
|
|
font=imps.PLT_TBL_FONT,
|
|
row_fill_color=imps.PLT_TBL_ROW_COLORS,
|
|
paper_bgcolor="rgba(0, 0, 0, 0)",
|
|
)
|
|
fig.update_traces(
|
|
cells=(
|
|
dict(
|
|
align=["center", "right"],
|
|
font=dict(color=font_color),
|
|
)
|
|
)
|
|
)
|
|
|
|
imagefile = imps.save_image("econ-overview.png", fig)
|
|
return {
|
|
"title": "Economy: [WSJ] Market Overview",
|
|
"imagefile": imagefile,
|
|
}
|