Files
OpenBB/discordbot/stocks/due_diligence/est.py
Artem Veremey 1e8daa1f9a Enabling pylint for DiscordBot (#979)
* Enabling markdown linting for DiscordBot

* Clearning remaining linters

* Enabling pylint for DiscordBot

* Fix DiscordBot imports, pylint and mypy

* Flake8 fixes

* Add an exception for too-many-branches
2021-11-24 17:15:42 -08:00

84 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import discord
import discordbot.config_discordbot as cfg
from discordbot.helpers import pagination
from gamestonk_terminal.stocks.due_diligence import business_insider_model
async def est_command(ctx, ticker=""):
"""Displays earning estimates [Business Insider]"""
try:
# Debug
if cfg.DEBUG:
print(f"!stocks.dd.est {ticker}")
# Check for argument
if ticker == "":
raise Exception("Stock ticker is required")
(
df_year_estimates,
df_quarter_earnings,
df_quarter_revenues,
) = business_insider_model.get_estimates(ticker)
if (
df_quarter_revenues.empty
and df_year_estimates.empty
and df_quarter_earnings.empty
):
raise Exception("Enter a valid ticker")
# Debug user output
if cfg.DEBUG:
print(df_year_estimates.to_string())
print(df_quarter_earnings.to_string())
print(df_quarter_revenues.to_string())
# Output data
cols = []
initial_text = (
"´´´Page 0: Overview\nPage 1: Year Estimates\n"
"Page 2: Quarter Earnings\nPage 3: Quarter Revenues´´´"
)
text = "´´´" + df_year_estimates.to_string() + "´´´"
cols.append(text)
text = "´´´" + df_quarter_earnings.to_string() + "´´´"
cols.append(text)
text = "´´´" + df_quarter_revenues.to_string() + "´´´"
cols.append(text)
columns = []
columns.append(
discord.Embed(
title="Stocks: [Business Insider] Earning Estimates",
description=initial_text,
colour=cfg.COLOR,
).set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
)
for text in cols:
columns.append(
discord.Embed(description=text, colour=cfg.COLOR,).set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
)
await pagination(columns, ctx)
except Exception as e:
embed = discord.Embed(
title="ERROR Stocks: [Business Insider] Earning Estimates",
colour=cfg.COLOR,
description=e,
)
embed.set_author(
name=cfg.AUTHOR_NAME,
icon_url=cfg.AUTHOR_ICON_URL,
)
await ctx.send(embed=embed)