def display_overview(export: str):
    """Market overview. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.market_overview()
    if df_data.empty:
        print("No overview data available\n")
        return

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df_data,
                showindex=False,
                headers=df_data.columns,
                floatfmt=".2f",
                tablefmt="fancy_grid",
            )
        )
    else:
        print(df_data.to_string(index=False))
    print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "overview",
        df_data,
    )
Beispiel #2
0
def display_overview(export: str):
    """Market overview. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.market_overview()
    if df_data.empty:
        console.print("No overview data available\n")
        return

    print_rich_table(
        df_data,
        show_index=False,
        headers=list(df_data.columns),
        title="Market Overview",
    )

    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "overview",
        df_data,
    )
Beispiel #3
0
def overview_command():
    """Market data overview [Wall St. Journal]"""
    # Debug user input
    if cfg.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["Price"] = pd.to_numeric(df["Price"].astype(float))
    df["Chg"] = pd.to_numeric(df["Chg"].astype(float))
    df["%Chg"] = pd.to_numeric(df["%Chg"].astype(float))

    formats = {"Price": "${:.2f}", "Chg": "${:.2f}", "%Chg": "{:.2f}%"}
    for col, v in formats.items():
        df[col] = df[col].map(lambda x: v.format(x))  # pylint: disable=W0640

    df = df[[
        " ",
        "Price",
        "Chg",
        "%Chg",
    ]]

    df = df.fillna("")
    df.set_index(" ", inplace=True)

    dindex = len(df.index)
    fig = df2img.plot_dataframe(
        df,
        fig_size=(800, (40 + (40 * dindex))),
        col_width=[8, 3, 3],
        tbl_cells=dict(
            align="left",
            height=35,
        ),
        template="plotly_dark",
        font=dict(
            family="Consolas",
            size=20,
        ),
        paper_bgcolor="rgba(0, 0, 0, 0)",
    )

    imagefile = save_image("econ-indices.png", fig)
    return {
        "title": "Economy: [WSJ] Market Overview",
        "imagefile": imagefile,
    }
Beispiel #4
0
async def overview_command(ctx):
    """Market data overview [Wall St. Journal]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            logger.debug("!economy.overview")

        # Retrieve data
        df_data = wsj_model.market_overview()

        # Debug user output
        if cfg.DEBUG:
            logger.debug(df_data.to_string())

        # Output data
        if df_data.empty:
            df_data_str = "No overview data available"
        else:
            df_data_str = "```" + df_data.to_string(index=False) + "```"

        embed = discord.Embed(
            title="Economy: [WSJ] Market Overview",
            description=df_data_str,
            colour=cfg.COLOR,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)

    except Exception as e:
        embed = discord.Embed(
            title="ERROR Economy: [WSJ] Market Overview",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)
Beispiel #5
0
async def overview_command(ctx):
    """Market data overview [Wall St. Journal]"""

    try:
        # Debug user input
        if cfg.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["Price"] = pd.to_numeric(df["Price"].astype(float))
        df["Chg"] = pd.to_numeric(df["Chg"].astype(float))
        df["%Chg"] = pd.to_numeric(df["%Chg"].astype(float))

        formats = {"Price": "${:.2f}", "Chg": "${:.2f}", "%Chg": "{:.2f}%"}
        for col, v in formats.items():
            df[col] = df[col].map(lambda x: v.format(x))  # pylint: disable=W0640

        df = df[[
            "Price",
            "Chg",
            "%Chg",
        ]]

        df = df.fillna("")
        df.set_index(" ", inplace=True)

        dindex = len(df.index)
        fig = df2img.plot_dataframe(
            df,
            fig_size=(800, (40 + (40 * dindex))),
            col_width=[8, 3, 3],
            tbl_cells=dict(
                align="left",
                height=35,
            ),
            template="plotly_dark",
            font=dict(
                family="Consolas",
                size=20,
            ),
            paper_bgcolor="rgba(0, 0, 0, 0)",
        )
        imagefile = "econ-indices.png"
        df2img.save_dataframe(fig=fig, filename=imagefile)

        image = Image.open(imagefile)
        image = autocrop_image(image, 0)
        image.save(imagefile, "PNG", quality=100)

        image = disnake.File(imagefile)

        title = "Economy: [WSJ] Market Overview"
        embed = disnake.Embed(title=title, colour=cfg.COLOR)
        embed.set_image(url=f"attachment://{imagefile}")
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )
        os.remove(imagefile)

        await ctx.send(embed=embed, file=image)

    except Exception as e:
        embed = disnake.Embed(
            title="ERROR Economy: [WSJ] Market Overview",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed, delete_after=30.0)
Beispiel #6
0
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,
    }
Beispiel #7
0
async def overview_command(ctx, arg=""):
    """Gets the market overview data from GST and sends it

    Parameters
    -----------
    arg: str
        -h or help

    Returns
    -------
    discord message
        Sends a message containing an embed of market overview data to the user
    """

    try:
        # Debug
        if cfg.DEBUG:
            print(f"!stocks.economy.overview {arg}")

        # Help
        if arg == "-h" or arg == "help":
            help_txt = "Market Overview [Source: Wall St. Journal]\n"
            embed = discord.Embed(
                title="Economy: [WSJ] Market Overview HELP",
                description=help_txt,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

        else:
            df_data = wsj_model.market_overview()
            if df_data.empty:
                df_data_str = "No overview data available"
            else:
                df_data_str = "```" + df_data.to_string(index=False) + "```"

            embed = discord.Embed(
                title="Economy: [WSJ] Market Overview",
                description=df_data_str,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

        await ctx.send(embed=embed)

    except Exception as e:
        title = "INTERNAL ERROR"
        embed = discord.Embed(title=title, colour=cfg.COLOR)
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )
        embed.set_description(
            "Try updating the bot, make sure DEBUG is True in the config "
            "and restart it.\nIf the error still occurs open a issue at: "
            "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
            f"\n{e}")
        await ctx.send(embed=embed)
        if cfg.DEBUG:
            print(e)