From f40ba0d256a78ab2b8461f0df3a9a52ca7dc5704 Mon Sep 17 00:00:00 2001 From: Theodore Aptekarev Date: Fri, 7 Jan 2022 22:30:09 +0300 Subject: [PATCH] Bot logging fix (#1105) * Write bot logs to stdout instead of a file Heroku's logging uses the stdout and has problems with files * Send "you snooze you lose" only if debug flag is enabled * Replace print statements with logger entries in the economy menu * Add logging to bot menu command calls * Silence bandit warnings about the REPLACE_ME token * Organize imports and update logging in economy menu * Organize imports and update logging in dps menu * Organize imports and update logging in dd menu * Organize imports and update logging in gov menu * Organize imports and update logging in options menu * Organize imports and update logging in screener menu * Organize imports and update logging in ta menu * Revert automatic import sorting * Add logging to the options reaction helper --- discordbot/config_discordbot.py | 2 +- discordbot/economy/currencies.py | 10 +-- discordbot/economy/economy_menu.py | 74 ++++++++-------- discordbot/economy/energy.py | 10 +-- discordbot/economy/feargreed.py | 22 +++-- discordbot/economy/futures.py | 10 +-- discordbot/economy/glbonds.py | 10 +-- discordbot/economy/grains.py | 10 +-- discordbot/economy/indices.py | 10 +-- discordbot/economy/meats.py | 8 +- discordbot/economy/metals.py | 8 +- discordbot/economy/overview.py | 8 +- discordbot/economy/performance.py | 15 ++-- discordbot/economy/softs.py | 8 +- discordbot/economy/usbonds.py | 8 +- discordbot/economy/valuation.py | 16 ++-- discordbot/reaction_helper.py | 39 ++++----- discordbot/run_discordbot.py | 17 ++-- discordbot/stocks/dark_pool_shorts/dpotc.py | 22 ++--- .../stocks/dark_pool_shorts/dps_menu.py | 39 ++++----- discordbot/stocks/dark_pool_shorts/ftd.py | 22 ++--- discordbot/stocks/dark_pool_shorts/hsi.py | 10 ++- discordbot/stocks/dark_pool_shorts/pos.py | 10 ++- discordbot/stocks/dark_pool_shorts/psi.py | 23 +++-- discordbot/stocks/dark_pool_shorts/shorted.py | 10 ++- discordbot/stocks/dark_pool_shorts/sidtc.py | 10 ++- discordbot/stocks/dark_pool_shorts/spos.py | 18 ++-- discordbot/stocks/due_diligence/analyst.py | 6 +- discordbot/stocks/due_diligence/arktrades.py | 9 +- discordbot/stocks/due_diligence/customer.py | 8 +- discordbot/stocks/due_diligence/dd_menu.py | 35 ++++---- discordbot/stocks/due_diligence/est.py | 14 +-- discordbot/stocks/due_diligence/pt.py | 13 +-- discordbot/stocks/due_diligence/sec.py | 8 +- discordbot/stocks/due_diligence/supplier.py | 8 +- discordbot/stocks/government/contracts.py | 13 +-- discordbot/stocks/government/gov_menu.py | 67 +++++++-------- discordbot/stocks/government/gtrades.py | 21 +++-- discordbot/stocks/government/histcont.py | 13 +-- discordbot/stocks/government/lastcontracts.py | 6 +- discordbot/stocks/government/lasttrades.py | 9 +- discordbot/stocks/government/lobbying.py | 6 +- discordbot/stocks/government/qtrcontracts.py | 11 +-- discordbot/stocks/government/topbuys.py | 19 +++-- discordbot/stocks/government/toplobbying.py | 11 +-- discordbot/stocks/government/topsells.py | 17 ++-- discordbot/stocks/options/calls.py | 3 +- discordbot/stocks/options/expirations.py | 3 +- discordbot/stocks/options/hist.py | 15 ++-- discordbot/stocks/options/iv.py | 7 +- discordbot/stocks/options/oi.py | 11 +-- discordbot/stocks/options/opt_cmd.py | 7 +- discordbot/stocks/options/options_menu.py | 66 +++++--------- discordbot/stocks/options/puts.py | 3 +- discordbot/stocks/options/unu.py | 8 +- discordbot/stocks/options/vol.py | 9 +- discordbot/stocks/screener/financial.py | 7 +- discordbot/stocks/screener/historical.py | 8 +- discordbot/stocks/screener/overview.py | 7 +- discordbot/stocks/screener/ownership.py | 7 +- discordbot/stocks/screener/performance.py | 7 +- discordbot/stocks/screener/presets_custom.py | 4 +- discordbot/stocks/screener/presets_default.py | 4 +- discordbot/stocks/screener/screener_menu.py | 44 +++++----- discordbot/stocks/screener/technical.py | 7 +- discordbot/stocks/screener/valuation.py | 7 +- discordbot/stocks/technical_analysis/ad.py | 9 +- discordbot/stocks/technical_analysis/adosc.py | 16 +++- discordbot/stocks/technical_analysis/adx.py | 15 +++- discordbot/stocks/technical_analysis/aroon.py | 13 ++- .../stocks/technical_analysis/bbands.py | 15 +++- discordbot/stocks/technical_analysis/cci.py | 13 ++- discordbot/stocks/technical_analysis/cg.py | 12 ++- .../stocks/technical_analysis/donchian.py | 13 ++- discordbot/stocks/technical_analysis/ema.py | 13 ++- discordbot/stocks/technical_analysis/fib.py | 11 ++- .../stocks/technical_analysis/fisher.py | 6 +- discordbot/stocks/technical_analysis/hma.py | 13 ++- discordbot/stocks/technical_analysis/kc.py | 16 +++- discordbot/stocks/technical_analysis/macd.py | 15 +++- discordbot/stocks/technical_analysis/obv.py | 11 ++- discordbot/stocks/technical_analysis/recom.py | 3 +- discordbot/stocks/technical_analysis/rsi.py | 15 +++- discordbot/stocks/technical_analysis/sma.py | 13 ++- discordbot/stocks/technical_analysis/stoch.py | 14 ++- .../stocks/technical_analysis/summary.py | 3 +- .../stocks/technical_analysis/ta_menu.py | 85 +++++++++---------- discordbot/stocks/technical_analysis/view.py | 6 +- discordbot/stocks/technical_analysis/wma.py | 13 ++- discordbot/stocks/technical_analysis/zlma.py | 13 ++- 90 files changed, 764 insertions(+), 569 deletions(-) diff --git a/discordbot/config_discordbot.py b/discordbot/config_discordbot.py index 97baf61e937..8bebf638288 100644 --- a/discordbot/config_discordbot.py +++ b/discordbot/config_discordbot.py @@ -22,7 +22,7 @@ COMMAND_PREFIX = "!" DATE_FORMAT = "%Y-%m-%d" COLOR = discord.Color.from_rgb(0, 206, 154) MENU_TIMEOUT = 30 -DEBUG = True +DEBUG = False GST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) diff --git a/discordbot/economy/currencies.py b/discordbot/economy/currencies.py index 052b4eded7a..f70a3f7b670 100644 --- a/discordbot/economy/currencies.py +++ b/discordbot/economy/currencies.py @@ -1,23 +1,21 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def currencies_command(ctx): """Currencies overview [Wall St. Journal]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.currencies") - # Retrieve data df_data = wsj_model.global_currencies() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/economy_menu.py b/discordbot/economy/economy_menu.py index ecce218cba3..7244a603238 100644 --- a/discordbot/economy/economy_menu.py +++ b/discordbot/economy/economy_menu.py @@ -1,25 +1,24 @@ import asyncio + import discord import discord_components import discordbot.config_discordbot as cfg - -from discordbot.run_discordbot import gst_bot - -from discordbot.economy.feargreed import feargreed_command -from discordbot.economy.overview import overview_command -from discordbot.economy.indices import indices_command -from discordbot.economy.futures import futures_command -from discordbot.economy.usbonds import usbonds_command -from discordbot.economy.glbonds import glbonds_command +from discordbot.run_discordbot import gst_bot, logger from discordbot.economy.currencies import currencies_command from discordbot.economy.energy import energy_command -from discordbot.economy.metals import metals_command +from discordbot.economy.feargreed import feargreed_command +from discordbot.economy.futures import futures_command +from discordbot.economy.glbonds import glbonds_command from discordbot.economy.grains import grains_command +from discordbot.economy.indices import indices_command from discordbot.economy.meats import meats_command -from discordbot.economy.softs import softs_command -from discordbot.economy.valuation import valuation_command +from discordbot.economy.metals import metals_command +from discordbot.economy.overview import overview_command from discordbot.economy.performance import performance_command +from discordbot.economy.softs import softs_command +from discordbot.economy.usbonds import usbonds_command +from discordbot.economy.valuation import valuation_command class EconomyCommands(discord.ext.commands.Cog): @@ -33,9 +32,9 @@ class EconomyCommands(discord.ext.commands.Cog): """CNN Fear and Greed Index [CNN] Parameters - ----------- + ---------- indicator: str - Possible indicatores are: jbd, mv, pco, mm, sps, spb, shd. Which stand for + Possible indicators are: jbd, mv, pco, mm, sps, spb, shd. Which stand for Junk Bond Demand, Market Volatility, Put and Call Options, Market Momentum, Stock Price Strength, Stock Price Breadth, Safe Heaven Demand. """ @@ -44,56 +43,67 @@ class EconomyCommands(discord.ext.commands.Cog): @discord.ext.commands.command(name="economy.overview") async def overview(self, ctx: discord.ext.commands.Context): """Market data overview [Wall St. Journal]""" + logger.info("economy.overview") await overview_command(ctx) @discord.ext.commands.command(name="economy.indices") async def indices(self, ctx: discord.ext.commands.Context): """US indices overview [Wall St. Journal]""" + logger.info("economy.indices") await indices_command(ctx) @discord.ext.commands.command(name="economy.futures") async def futures(self, ctx: discord.ext.commands.Context): """Futures and commodities overview [Wall St. Journal]""" + logger.info("economy.futures") await futures_command(ctx) @discord.ext.commands.command(name="economy.usbonds") async def usbonds(self, ctx: discord.ext.commands.Context): """US bonds overview [Wall St. Journal]""" + logger.info("economy.usbonds") await usbonds_command(ctx) @discord.ext.commands.command(name="economy.glbonds") async def glbonds(self, ctx: discord.ext.commands.Context): """Global bonds overview [Wall St. Journal]""" + logger.info("economy.glbonds") await glbonds_command(ctx) @discord.ext.commands.command(name="economy.energy") async def energy(self, ctx: discord.ext.commands.Context): """Displays energy futures data [Finviz]""" + logger.info("economy.energy") await energy_command(ctx) @discord.ext.commands.command(name="economy.metals") async def metals(self, ctx: discord.ext.commands.Context): """Displays metals futures data [Finviz]""" + logger.info("economy.metals") await metals_command(ctx) @discord.ext.commands.command(name="economy.meats") async def meats(self, ctx: discord.ext.commands.Context): """Displays meats futures data [Finviz]""" + logger.info("economy.meats") await meats_command(ctx) @discord.ext.commands.command(name="economy.grains") async def grains(self, ctx: discord.ext.commands.Context): """Displays grains futures data [Finviz]""" + logger.info("economy.grains") await grains_command(ctx) @discord.ext.commands.command(name="economy.softs") async def softs(self, ctx: discord.ext.commands.Context): """Displays softs futures data [Finviz]""" + logger.info("economy.softs") await softs_command(ctx) @discord.ext.commands.command(name="economy.currencies") async def currencies(self, ctx: discord.ext.commands.Context): """Currencies overview [Wall St. Journal]""" + logger.info("economy.currencies") await currencies_command(ctx) @discord.ext.commands.command(name="economy.valuation") @@ -107,6 +117,7 @@ class EconomyCommands(discord.ext.commands.Cog): consumer_cyclical, consumer_defensive, energy, financial, healthcare, industrials, real_estate, technology, utilities, country, capitalization. """ + logger.info("economy.valuation") await valuation_command(ctx, economy_group) @discord.ext.commands.command(name="economy.performance") @@ -120,6 +131,7 @@ class EconomyCommands(discord.ext.commands.Cog): consumer_cyclical, consumer_defensive, energy, financial, healthcare, industrials, real_estate, technology, utilities, country, capitalization. """ + logger.info("economy.performance") await performance_command(ctx, economy_group) @discord.ext.commands.command(name="economy") @@ -133,9 +145,7 @@ class EconomyCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the economy context. The user can then select a reaction to trigger a command. """ - - if cfg.DEBUG: - print("!economy") + logger.info("!economy") cols_temp = [] cols = [] @@ -258,56 +268,46 @@ class EconomyCommands(discord.ext.commands.Cog): async def on_reaction_add(reaction, user): if user == ctx.message.author and str(reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("!economy. Reaction selected: 0") if current == 0: await overview_command(ctx) elif current == 1: await metals_command(ctx) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("!economy. Reaction selected: 1") if current == 0: await futures_command(ctx) elif current == 1: await meats_command(ctx) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("!economy. Reaction selected: 2") if current == 0: await usbonds_command(ctx) elif current == 1: await grains_command(ctx) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("!economy. Reaction selected: 3") if current == 0: await glbonds_command(ctx) elif current == 1: await softs_command(ctx) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("!economy. Reaction selected: 4") await indices_command(ctx) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("!economy. Reaction selected: 5") await currencies_command(ctx) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("!economy. Reaction selected: 6") await feargreed_command(ctx) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("!economy. Reaction selected: 7") await valuation_command(ctx) elif reaction.emoji == "8️⃣": - if cfg.DEBUG: - print("Reaction selected: 8") + logger.info("!economy. Reaction selected: 8") await performance_command(ctx) elif reaction.emoji == "9️⃣": - if cfg.DEBUG: - print("Reaction selected: 9") + logger.info("!economy. Reaction selected: 9") await energy_command(ctx) for emoji in emoji_list: await main_message.remove_reaction(emoji, ctx.bot.user) diff --git a/discordbot/economy/energy.py b/discordbot/economy/energy.py index 41c8f0b7a8f..232e5455af5 100644 --- a/discordbot/economy/energy.py +++ b/discordbot/economy/energy.py @@ -1,18 +1,16 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def energy_command(ctx): """Displays energy futures data [Finviz]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.energy") - # Retrieve data d_futures = finviz_model.get_futures() @@ -22,7 +20,7 @@ async def energy_command(ctx): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data if df.empty: diff --git a/discordbot/economy/feargreed.py b/discordbot/economy/feargreed.py index 9740ce7a003..f42ee7cef09 100644 --- a/discordbot/economy/feargreed.py +++ b/discordbot/economy/feargreed.py @@ -1,27 +1,25 @@ -import os import datetime -import matplotlib.pyplot as plt -import discord +import os + +import discord +import matplotlib.pyplot as plt + +from gamestonk_terminal.economy import cnn_model, cnn_view -from gamestonk_terminal.economy import cnn_view, cnn_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def feargreed_command(ctx, indicator=""): """CNN Fear and Greed Index [CNN]""" try: - # Debug user input - if cfg.DEBUG: - print(f"\n!economy.feargreed {indicator}") - # Check for argument possible_indicators = ("", "jbd", "mv", "pco", "mm", "sps", "spb", "shd") if indicator not in possible_indicators: raise Exception( - f"Select a valid indicator from {', '.join(possible_indicators)}" + f"Select a valid indicator from {', '.join(possible_indicators)}" # nosec ) # Retrieve data @@ -68,12 +66,12 @@ async def feargreed_command(ctx, indicator=""): embed.set_image(url=uploaded_image.link) else: - if cfg.DEBUG: - print("Error with uploading the the image to Imgur.") + logger.error("Error when uploading the the image to Imgur.") await ctx.send(embed=embed) except Exception as e: + logger.error("ERROR Economy: [CNN] Feargreed. %s", e) embed = discord.Embed( title="ERROR Economy: [CNN] Feargreed", colour=cfg.COLOR, diff --git a/discordbot/economy/futures.py b/discordbot/economy/futures.py index 7a18c826ae4..54d7ceb2b3c 100644 --- a/discordbot/economy/futures.py +++ b/discordbot/economy/futures.py @@ -1,23 +1,21 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def futures_command(ctx): """Futures and commodities overview [Wall St. Journal]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.futures") - # Retrieve data df_data = wsj_model.top_commodities() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/glbonds.py b/discordbot/economy/glbonds.py index 3e3dcd7326e..09f19d347b9 100644 --- a/discordbot/economy/glbonds.py +++ b/discordbot/economy/glbonds.py @@ -1,23 +1,21 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def glbonds_command(ctx): """Global bonds overview [Wall St. Journal]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.glbonds") - # Retrieve data df_data = wsj_model.global_bonds() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/grains.py b/discordbot/economy/grains.py index 1a678004253..1125224a612 100644 --- a/discordbot/economy/grains.py +++ b/discordbot/economy/grains.py @@ -1,18 +1,16 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def grains_command(ctx): """Displays grains futures data [Finviz]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.grains") - # Retrieve data d_futures = finviz_model.get_futures() @@ -22,7 +20,7 @@ async def grains_command(ctx): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data if df.empty: diff --git a/discordbot/economy/indices.py b/discordbot/economy/indices.py index 8162d5e6942..34f47488545 100644 --- a/discordbot/economy/indices.py +++ b/discordbot/economy/indices.py @@ -1,23 +1,21 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def indices_command(ctx): """US indices overview [Wall St. Journal]""" try: - # Debug user input - if cfg.DEBUG: - print("\n!economy.indices") - # Retrieve data df_data = wsj_model.us_indices() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/meats.py b/discordbot/economy/meats.py index 0234b70fd4c..604f102c0db 100644 --- a/discordbot/economy/meats.py +++ b/discordbot/economy/meats.py @@ -1,9 +1,11 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def meats_command(ctx): """Displays meats futures data [Finviz]""" @@ -11,7 +13,7 @@ async def meats_command(ctx): try: # Debug user input if cfg.DEBUG: - print("\n!economy.meats") + logger.debug("!economy.meats") # Retrieve data d_futures = finviz_model.get_futures() @@ -22,7 +24,7 @@ async def meats_command(ctx): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data if df.empty: diff --git a/discordbot/economy/metals.py b/discordbot/economy/metals.py index 932d4517056..e730470bc03 100644 --- a/discordbot/economy/metals.py +++ b/discordbot/economy/metals.py @@ -1,9 +1,11 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def metals_command(ctx): """Displays metals futures data [Finviz]""" @@ -11,7 +13,7 @@ async def metals_command(ctx): try: # Debug user input if cfg.DEBUG: - print("\n!economy.metals") + logger.debug("!economy.metals") # Retrieve data d_futures = finviz_model.get_futures() @@ -22,7 +24,7 @@ async def metals_command(ctx): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data if df.empty: diff --git a/discordbot/economy/overview.py b/discordbot/economy/overview.py index 79ba420accd..8f991c068ce 100644 --- a/discordbot/economy/overview.py +++ b/discordbot/economy/overview.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def overview_command(ctx): """Market data overview [Wall St. Journal]""" @@ -10,14 +12,14 @@ async def overview_command(ctx): try: # Debug user input if cfg.DEBUG: - print("\n!economy.overview") + logger.debug("!economy.overview") # Retrieve data df_data = wsj_model.market_overview() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/performance.py b/discordbot/economy/performance.py index a02377494c1..02cf3f124df 100644 --- a/discordbot/economy/performance.py +++ b/discordbot/economy/performance.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def performance_command(ctx, economy_group="sector"): """Performance of sectors, industry, country [Finviz]""" @@ -29,19 +31,20 @@ async def performance_command(ctx, economy_group="sector"): try: # Debug user input if cfg.DEBUG: - print(f"\n!economy.performance {economy_group}") + logger.debug("!economy.performance %s", economy_group) # Select default group if not economy_group: if cfg.DEBUG: - print("Use default economy_group: 'sector'") + logger.debug("Use default economy_group: 'sector'") economy_group = "sector" # Check for argument possible_groups = list(d_economy_group.keys()) if economy_group not in possible_groups: - raise Exception(f"Select a valid group from {', '.join(possible_groups)}") + possible_group_list = ", ".join(possible_groups) + raise Exception(f"Select a valid group from {possible_group_list}") # nosec group = d_economy_group[economy_group] @@ -50,7 +53,7 @@ async def performance_command(ctx, economy_group="sector"): # Debug user output if cfg.DEBUG: - print(df_group.to_string()) + logger.debug(df_group.to_string()) # Output data future_column_name = df_group["Name"] diff --git a/discordbot/economy/softs.py b/discordbot/economy/softs.py index 8beea0d6d31..427ebf4fce7 100644 --- a/discordbot/economy/softs.py +++ b/discordbot/economy/softs.py @@ -1,9 +1,11 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def softs_command(ctx): """Displays softs futures data [Finviz]""" @@ -11,7 +13,7 @@ async def softs_command(ctx): try: # Debug user input if cfg.DEBUG: - print("\n!economy.softs") + logger.debug("!economy.softs") # Retrieve data d_futures = finviz_model.get_futures() @@ -22,7 +24,7 @@ async def softs_command(ctx): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data if df.empty: diff --git a/discordbot/economy/usbonds.py b/discordbot/economy/usbonds.py index 0c1215b4332..04aa962be27 100644 --- a/discordbot/economy/usbonds.py +++ b/discordbot/economy/usbonds.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.economy import wsj_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def usbonds_command(ctx): """US bonds overview [Wall St. Journal]""" @@ -10,14 +12,14 @@ async def usbonds_command(ctx): try: # Debug user input if cfg.DEBUG: - print("\n!economy.usbonds") + logger.debug("!economy.usbonds") # Retrieve data df_data = wsj_model.us_bonds() # Debug user output if cfg.DEBUG: - print(df_data.to_string()) + logger.debug(df_data.to_string()) # Output data if df_data.empty: diff --git a/discordbot/economy/valuation.py b/discordbot/economy/valuation.py index a64ba8461b1..97261bdc0c5 100644 --- a/discordbot/economy/valuation.py +++ b/discordbot/economy/valuation.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.economy import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def valuation_command(ctx, economy_group="sector"): """Valuation of sectors, industry, country [Finviz]""" @@ -29,19 +31,21 @@ async def valuation_command(ctx, economy_group="sector"): try: # Debug user input if cfg.DEBUG: - print(f"\n!economy.valuation {economy_group}") + logger.debug("!economy.valuation %s", economy_group) # Select default group if economy_group == "": if cfg.DEBUG: - print("Use default economy_group: 'sector'") + logger.debug("Use default economy_group: 'sector'") economy_group = "sector" # Check for argument possible_groups = list(d_economy_group.keys()) if economy_group not in possible_groups: - raise Exception(f"Select a valid group from {', '.join(possible_groups)}") + raise Exception( + f"Select a valid group from {', '.join(possible_groups)}" # nosec + ) group = d_economy_group[economy_group] @@ -50,7 +54,7 @@ async def valuation_command(ctx, economy_group="sector"): # Debug user output if cfg.DEBUG: - print(df_group.to_string()) + logger.debug(df_group.to_string()) # Output data future_column_name = df_group["Name"] diff --git a/discordbot/reaction_helper.py b/discordbot/reaction_helper.py index b4f54f34986..6c5a4e9ad56 100644 --- a/discordbot/reaction_helper.py +++ b/discordbot/reaction_helper.py @@ -3,12 +3,13 @@ import discord from gamestonk_terminal.config_terminal import TRADIER_TOKEN from gamestonk_terminal.stocks.options import tradier_model, yfinance_model -from discordbot.run_discordbot import gst_bot + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_bot, logger async def expiry_dates_reaction(ctx, ticker, expiry, func_cmd, call_arg: tuple = None): - if TRADIER_TOKEN == "REPLACE_ME": + if TRADIER_TOKEN == "REPLACE_ME": # nosec dates = yfinance_model.option_expirations(ticker) else: dates = tradier_model.option_expirations(ticker) @@ -100,13 +101,12 @@ async def expiry_dates_reaction(ctx, ticker, expiry, func_cmd, call_arg: tuple = ) for N in range(0, 10): if reaction.emoji == emoji_list[N]: - if cfg.DEBUG: - print(f"Reaction selected: {N}") - expiry = dates[N] - if call_arg is None: - await func_cmd(ctx, ticker, expiry) - else: - await func_cmd(ctx, ticker, expiry, *call_arg) + logger.info("Reaction selected: %d", N) + expiry = dates[N] + if call_arg is None: + await func_cmd(ctx, ticker, expiry) + else: + await func_cmd(ctx, ticker, expiry, *call_arg) for emoji in emoji_list: await msg.remove_reaction(emoji, ctx.bot.user) @@ -114,13 +114,14 @@ async def expiry_dates_reaction(ctx, ticker, expiry, func_cmd, call_arg: tuple = except asyncio.TimeoutError: for emoji in emoji_list: await msg.remove_reaction(emoji, ctx.bot.user) - embed = discord.Embed( - description="Error timeout - you snooze you lose! 😋", - colour=cfg.COLOR, - title="TIMEOUT " + ticker.upper() + " Options: Expiry Date", - ) - embed.set_author( - name=cfg.AUTHOR_NAME, - icon_url=cfg.AUTHOR_ICON_URL, - ) - await ctx.send(embed=embed, delete_after=10.0) + if cfg.DEBUG: + embed = discord.Embed( + description="Error timeout - you snooze you lose! 😋", + colour=cfg.COLOR, + title="TIMEOUT " + ticker.upper() + " Options: Expiry Date", + ) + embed.set_author( + name=cfg.AUTHOR_NAME, + icon_url=cfg.AUTHOR_ICON_URL, + ) + await ctx.send(embed=embed, delete_after=10.0) diff --git a/discordbot/run_discordbot.py b/discordbot/run_discordbot.py index 77db4348137..15ac3816fac 100644 --- a/discordbot/run_discordbot.py +++ b/discordbot/run_discordbot.py @@ -2,7 +2,6 @@ import difflib import logging import os import sys -from datetime import datetime import discord import discord_components @@ -13,13 +12,7 @@ import config_discordbot as cfg # Logging logger = logging.getLogger("discord") logging.basicConfig(level=logging.INFO) # DEBUG/INFO/WARNING/ERROR/CRITICAL -handler = logging.FileHandler( - filename=os.path.join( - os.path.dirname(__file__), "..", "logs", f"{datetime.now()}_bot.log" - ), - encoding="utf-8", - mode="w", -) +handler = logging.StreamHandler(sys.stdout) handler.setFormatter( logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s") ) @@ -61,15 +54,15 @@ gst_bot = discord.ext.commands.Bot( discord_components.DiscordComponents(gst_bot) if cfg.IMGUR_CLIENT_ID == "REPLACE_ME" or cfg.DISCORD_BOT_TOKEN == "REPLACE_ME": - print( - "Update IMGUR_CLIENT_ID or DISCORD_BOT_TOKEN or both in " - + f"{ os.path.join('discordbot', 'config_discordbot') } \n" + logger.info( + "Update IMGUR_CLIENT_ID or DISCORD_BOT_TOKEN or both in %s \n", + os.path.join("discordbot", "config_discordbot"), ) sys.exit() async def on_ready(): - print("GST Discord Bot Ready to Gamestonk!") + logger.info("GST Discord Bot Ready to Gamestonk!") gst_imgur = pyimgur.Imgur(cfg.IMGUR_CLIENT_ID) diff --git a/discordbot/stocks/dark_pool_shorts/dpotc.py b/discordbot/stocks/dark_pool_shorts/dpotc.py index 0ff7c76ef7d..5e64f0b1c18 100644 --- a/discordbot/stocks/dark_pool_shorts/dpotc.py +++ b/discordbot/stocks/dark_pool_shorts/dpotc.py @@ -1,14 +1,16 @@ import os -import matplotlib.dates as mdates -import discord -from matplotlib import pyplot as plt -import yfinance as yf -import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur -from gamestonk_terminal.config_plot import PLOT_DPI +import discord +import matplotlib.dates as mdates +import yfinance as yf +from matplotlib import pyplot as plt + +from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.stocks.dark_pool_shorts import finra_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_imgur, logger + async def dpotc_command(ctx, ticker=""): """Dark pools (ATS) vs OTC data [FINRA]""" @@ -16,7 +18,7 @@ async def dpotc_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.dpotc {ticker}") + logger.debug("!stocks.dps.dpotc %s", ticker) # Check for argument if ticker == "": @@ -33,8 +35,8 @@ async def dpotc_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(ats.to_string()) - print(otc.to_string()) + logger.debug(ats.to_string()) + logger.debug(otc.to_string()) # Output data title = f"Stocks: [FINRA] Dark Pools (ATS) vs OTC {ticker}" diff --git a/discordbot/stocks/dark_pool_shorts/dps_menu.py b/discordbot/stocks/dark_pool_shorts/dps_menu.py index d43db4f55b3..abccaca7a41 100644 --- a/discordbot/stocks/dark_pool_shorts/dps_menu.py +++ b/discordbot/stocks/dark_pool_shorts/dps_menu.py @@ -3,8 +3,7 @@ import discord import yfinance as yf import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_bot - +from discordbot.run_discordbot import gst_bot, logger from discordbot.stocks.dark_pool_shorts.shorted import shorted_command from discordbot.stocks.dark_pool_shorts.ftd import ftd_command from discordbot.stocks.dark_pool_shorts.dpotc import dpotc_command @@ -37,6 +36,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): num: int Number of the most shorted stocks to retrieve """ + logger.info("stocks.dps.shorted") await shorted_command(ctx, num) @discord.ext.commands.command( @@ -51,6 +51,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): num: int Number of top stocks to print """ + logger.info("stocks.dps.hsi") await hsi_command(ctx, num) @discord.ext.commands.command( @@ -70,6 +71,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): num: int Number of top tickers to show """ + logger.info("stocks.dps.pos") await pos_command(ctx, sort, num) @discord.ext.commands.command( @@ -87,6 +89,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): num: int Number of top tickers to show """ + logger.info("stocks.dps.sidtc") await sidtc_command(ctx, sort, num) @discord.ext.commands.command( @@ -105,6 +108,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): end: datetime Ending date in YYYY-MM-DD format """ + logger.info("stocks.dps.ftd") await ftd_command(ctx, ticker, start, end) @discord.ext.commands.command( @@ -119,6 +123,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): ticker: str Stock ticker """ + logger.info("stocks.dps.dpotc") await dpotc_command(ctx, ticker) @discord.ext.commands.command( @@ -133,6 +138,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): ticker: str Stock ticker """ + logger.info("stocks.dps.spos") await spos_command(ctx, ticker) @discord.ext.commands.command( @@ -147,6 +153,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): ticker: str Stock ticker """ + logger.info("stocks.dps.psi") await psi_command(ctx, ticker) @discord.ext.commands.command( @@ -164,9 +171,7 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the dps context. The user can then select a reaction to trigger a command. """ - - if cfg.DEBUG: - print(f"\n!stocks.dps {ticker}") + logger.info("!stocks.dps %s", ticker) if ticker: stock = yf.download(ticker, progress=False) @@ -227,36 +232,28 @@ class DarkPoolShortsCommands(discord.ext.commands.Cog): "reaction_add", timeout=cfg.MENU_TIMEOUT, check=check ) if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("!stocks.dps. Reaction selected: 0") await shorted_command(ctx) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("!stocks.dps. Reaction selected: 1") await hsi_command(ctx) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("!stocks.dps. Reaction selected: 2") await pos_command(ctx) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("!stocks.dps. Reaction selected: 3") await sidtc_command(ctx) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("!stocks.dps. Reaction selected: 4") await ftd_command(ctx, ticker) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("!stocks.dps. Reaction selected: 5") await dpotc_command(ctx, ticker) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("!stocks.dps. Reaction selected: 6") await spos_command(ctx, ticker) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("!stocks.dps. Reaction selected: 7") await psi_command(ctx, ticker) for emoji in emoji_list: diff --git a/discordbot/stocks/dark_pool_shorts/ftd.py b/discordbot/stocks/dark_pool_shorts/ftd.py index c8de6a70411..8a6cd03a269 100644 --- a/discordbot/stocks/dark_pool_shorts/ftd.py +++ b/discordbot/stocks/dark_pool_shorts/ftd.py @@ -1,16 +1,18 @@ import os from datetime import datetime, timedelta -import discord -from matplotlib import pyplot as plt -import matplotlib.dates as mdates -import yfinance as yf -import discordbot.config_discordbot as cfg -import discordbot.helpers -from discordbot.run_discordbot import gst_imgur -from gamestonk_terminal.config_plot import PLOT_DPI +import discord +import yfinance as yf +import matplotlib.dates as mdates +from matplotlib import pyplot as plt + +from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.stocks.dark_pool_shorts import sec_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_imgur, logger +import discordbot.helpers + async def ftd_command(ctx, ticker="", start="", end=""): """Fails-to-deliver data [SEC]""" @@ -18,7 +20,7 @@ async def ftd_command(ctx, ticker="", start="", end=""): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.ftd {ticker} {start} {end}") + logger.debug("!stocks.dps.ftd %s %s %s", ticker, start, end) # Check for argument if ticker == "": @@ -45,7 +47,7 @@ async def ftd_command(ctx, ticker="", start="", end=""): # Debug user output if cfg.DEBUG: - print(ftds_data.to_string()) + logger.debug(ftds_data.to_string()) plt.figure(dpi=PLOT_DPI) # Output data diff --git a/discordbot/stocks/dark_pool_shorts/hsi.py b/discordbot/stocks/dark_pool_shorts/hsi.py index 65c430cac13..809b8fadf6b 100644 --- a/discordbot/stocks/dark_pool_shorts/hsi.py +++ b/discordbot/stocks/dark_pool_shorts/hsi.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.stocks.dark_pool_shorts import shortinterest_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def hsi_command(ctx, num="10"): """Show top high short interest stocks of over 20% ratio [shortinterest.com]""" @@ -11,7 +13,7 @@ async def hsi_command(ctx, num="10"): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.hsi {num}") + logger.debug("!stocks.dps.hsi %s", num) # Check for argument if not num.lstrip("-").isnumeric(): @@ -28,7 +30,7 @@ async def hsi_command(ctx, num="10"): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data future_column_name = df["Ticker"] diff --git a/discordbot/stocks/dark_pool_shorts/pos.py b/discordbot/stocks/dark_pool_shorts/pos.py index 4ab57032214..b391272c756 100644 --- a/discordbot/stocks/dark_pool_shorts/pos.py +++ b/discordbot/stocks/dark_pool_shorts/pos.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.stocks.dark_pool_shorts import stockgrid_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def pos_command(ctx, sort="dpp_dollar", num="10"): """Dark pool short position [Stockgrid]""" @@ -11,7 +13,7 @@ async def pos_command(ctx, sort="dpp_dollar", num="10"): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.pos {sort} {num}") + logger.debug("!stocks.dps.pos %s %s", sort, num) # Check for argument possible_sorts = ("sv", "sv_pct", "nsv", "nsv_dollar", "dpp", "dpp_dollar") @@ -33,7 +35,7 @@ async def pos_command(ctx, sort="dpp_dollar", num="10"): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data dp_date = df["Date"].values[0] diff --git a/discordbot/stocks/dark_pool_shorts/psi.py b/discordbot/stocks/dark_pool_shorts/psi.py index a2d6c73e256..9f037891bdc 100644 --- a/discordbot/stocks/dark_pool_shorts/psi.py +++ b/discordbot/stocks/dark_pool_shorts/psi.py @@ -1,14 +1,16 @@ import os from datetime import timedelta -import discord -from matplotlib import pyplot as plt -import yfinance as yf -import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur -from gamestonk_terminal.config_plot import PLOT_DPI +import discord +import yfinance as yf +from matplotlib import pyplot as plt + +from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.stocks.dark_pool_shorts import stockgrid_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_imgur, logger + async def psi_command(ctx, ticker=""): """Price vs short interest volume [Stockgrid]""" @@ -16,7 +18,7 @@ async def psi_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.psi {ticker}") + logger.debug("!stocks.dps.psi %s", ticker) # Check for argument if ticker == "": @@ -33,7 +35,7 @@ async def psi_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data title = f"Stocks: [Stockgrid] Price vs Short Interest Volume {ticker}" @@ -70,7 +72,10 @@ async def psi_command(ctx, ticker=""): axes[0].set_ylabel("Volume (1M)") ax2 = axes[0].twinx() ax2.plot( - df["date"].values, prices[len(prices) - len(df) :], c="k", label="Price" + df["date"].values, + prices[len(prices) - len(df) :], # noqa: E203 + c="k", + label="Price", ) ax2.set_ylabel("Price ($)") diff --git a/discordbot/stocks/dark_pool_shorts/shorted.py b/discordbot/stocks/dark_pool_shorts/shorted.py index 6857de2a536..bc0f46144eb 100644 --- a/discordbot/stocks/dark_pool_shorts/shorted.py +++ b/discordbot/stocks/dark_pool_shorts/shorted.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.stocks.dark_pool_shorts import yahoofinance_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def shorted_command(ctx, num="10"): """Show most shorted stocks [Yahoo Finance]""" @@ -11,7 +13,7 @@ async def shorted_command(ctx, num="10"): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.shorted {num}") + logger.debug("!stocks.dps.shorted %s", num) # Check for argument if not num.lstrip("-").isnumeric(): @@ -27,7 +29,7 @@ async def shorted_command(ctx, num="10"): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data df.dropna(how="all", axis=1, inplace=True) diff --git a/discordbot/stocks/dark_pool_shorts/sidtc.py b/discordbot/stocks/dark_pool_shorts/sidtc.py index 8c9d12d8cc1..23b7aff1335 100644 --- a/discordbot/stocks/dark_pool_shorts/sidtc.py +++ b/discordbot/stocks/dark_pool_shorts/sidtc.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.stocks.dark_pool_shorts import stockgrid_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def sidtc_command(ctx, sort="float", num="10"): """Short interest and days to cover [Stockgrid]""" @@ -11,7 +13,7 @@ async def sidtc_command(ctx, sort="float", num="10"): try: # Debug if cfg.DEBUG: - print(f"\n!stocks.dps.sidtc {sort} {num}") + logger.debug("!stocks.dps.sidtc %s %s", sort, num) # Check for argument possible_sorts = ("float", "dtc", "si") @@ -33,7 +35,7 @@ async def sidtc_command(ctx, sort="float", num="10"): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data dp_date = df["Date"].values[0] diff --git a/discordbot/stocks/dark_pool_shorts/spos.py b/discordbot/stocks/dark_pool_shorts/spos.py index a11c426e232..3b6bb91ed90 100644 --- a/discordbot/stocks/dark_pool_shorts/spos.py +++ b/discordbot/stocks/dark_pool_shorts/spos.py @@ -1,13 +1,15 @@ import os -import discord -from matplotlib import pyplot as plt -import yfinance as yf -import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur -from gamestonk_terminal.config_plot import PLOT_DPI +import discord +import yfinance as yf +from matplotlib import pyplot as plt + +from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.stocks.dark_pool_shorts import stockgrid_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_imgur, logger + async def spos_command(ctx, ticker=""): """Net short vs position [Stockgrid]""" @@ -15,7 +17,7 @@ async def spos_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"\n!stocks.dps.spos {ticker}") + logger.debug("!stocks.dps.spos %s", ticker) # Check for argument if ticker == "": @@ -32,7 +34,7 @@ async def spos_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(df.to_string()) + logger.debug(df.to_string()) # Output data title = f"Stocks: [Stockgrid] Net Short vs Position {ticker}" diff --git a/discordbot/stocks/due_diligence/analyst.py b/discordbot/stocks/due_diligence/analyst.py index 339a0967704..e4ceeaeace5 100644 --- a/discordbot/stocks/due_diligence/analyst.py +++ b/discordbot/stocks/due_diligence/analyst.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.stocks.due_diligence import finviz_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def analyst_command(ctx, ticker=""): """Displays analyst recommendations [Finviz]""" @@ -11,7 +13,7 @@ async def analyst_command(ctx, ticker=""): # Debug if cfg.DEBUG: - print(f"!stocks.dd.analyst {ticker}") + logger.debug("!stocks.dd.analyst %s", ticker) # Check for argument if ticker == "": diff --git a/discordbot/stocks/due_diligence/arktrades.py b/discordbot/stocks/due_diligence/arktrades.py index da487cb93f4..73ab5e6be65 100644 --- a/discordbot/stocks/due_diligence/arktrades.py +++ b/discordbot/stocks/due_diligence/arktrades.py @@ -1,11 +1,12 @@ import discord import pandas as pd -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination - from gamestonk_terminal.stocks.due_diligence import ark_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def arktrades_command(ctx, ticker="", num=""): """Displays trades made by ark [cathiesark.com]""" @@ -13,7 +14,7 @@ async def arktrades_command(ctx, ticker="", num=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.dd.arktrades{ticker}") + logger.debug("!stocks.dd.arktrades %s", ticker) if num == "": pass diff --git a/discordbot/stocks/due_diligence/customer.py b/discordbot/stocks/due_diligence/customer.py index dea344b84b0..2a1f563e1f6 100644 --- a/discordbot/stocks/due_diligence/customer.py +++ b/discordbot/stocks/due_diligence/customer.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.stocks.due_diligence import csimarket_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def customer_command(ctx, ticker=""): """Displays customers of the company [CSIMarket]""" @@ -10,7 +12,7 @@ async def customer_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.dd.customer {ticker}") + logger.debug("!stocks.dd.customer %s", ticker) if ticker == "": raise Exception("A ticker is required") @@ -22,7 +24,7 @@ async def customer_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(tickers) + logger.debug(tickers) # Output data embed = discord.Embed( diff --git a/discordbot/stocks/due_diligence/dd_menu.py b/discordbot/stocks/due_diligence/dd_menu.py index cc831a945a9..54fbcbd40d8 100644 --- a/discordbot/stocks/due_diligence/dd_menu.py +++ b/discordbot/stocks/due_diligence/dd_menu.py @@ -1,9 +1,8 @@ import asyncio import discord -from discordbot.run_discordbot import gst_bot import discordbot.config_discordbot as cfg - +from discordbot.run_discordbot import gst_bot, logger from discordbot.stocks.due_diligence.analyst import analyst_command from discordbot.stocks.due_diligence.pt import pt_command from discordbot.stocks.due_diligence.est import est_command @@ -28,6 +27,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.dd.analyst") await analyst_command(ctx, ticker) @discord.ext.commands.command(name="stocks.dd.pt", usage="[ticker] [raw] [start]") @@ -43,6 +43,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): start: Starting date in YYYY-MM-DD format """ + logger.info("stocks.dd.pt") await pt_command(ctx, ticker, raw, start) @discord.ext.commands.command(name="stocks.dd.est", usage="[ticker]") @@ -54,6 +55,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.dd.est") await est_command(ctx, ticker) @discord.ext.commands.command(name="stocks.dd.sec", usage="[ticker]") @@ -65,6 +67,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.dd.sec") await sec_command(ctx, ticker) @discord.ext.commands.command(name="stocks.dd.supplier", usage="[ticker]") @@ -76,6 +79,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.dd.supplier") await supplier_command(ctx, ticker) @discord.ext.commands.command(name="stocks.dd.customer", usage="[ticker]") @@ -87,6 +91,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.dd.customer") await customer_command(ctx, ticker) @discord.ext.commands.command(name="stocks.dd.arktrades", usage="[ticker] [num]") @@ -100,6 +105,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): num: int number of rows displayed """ + logger.info("stocks.dd.arktrades") await arktrades_command(ctx, ticker, num) @discord.ext.commands.command(name="stocks.dd") @@ -113,9 +119,7 @@ class DueDiligenceCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the dd context. The user can then select a reaction to trigger a command. """ - - if cfg.DEBUG: - print("!stocks.dd") + logger.info("!stocks.dd") if ticker == "": embed = discord.Embed( @@ -159,32 +163,25 @@ class DueDiligenceCommands(discord.ext.commands.Cog): "reaction_add", timeout=cfg.MENU_TIMEOUT, check=check ) if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("!stocks.dd. Reaction selected: 0") await analyst_command(ctx, ticker) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("!stocks.dd. Reaction selected: 1") await pt_command(ctx, ticker) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("!stocks.dd. Reaction selected: 2") await est_command(ctx, ticker) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("!stocks.dd. Reaction selected: 3") await sec_command(ctx, ticker) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("!stocks.dd. Reaction selected: 4") await supplier_command(ctx, ticker) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("!stocks.dd. Reaction selected: 5") await customer_command(ctx, ticker) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("!stocks.dd. Reaction selected: 6") await arktrades_command(ctx, ticker) for emoji in emoji_list: diff --git a/discordbot/stocks/due_diligence/est.py b/discordbot/stocks/due_diligence/est.py index 5641090bf7e..58fa9d4bf2a 100644 --- a/discordbot/stocks/due_diligence/est.py +++ b/discordbot/stocks/due_diligence/est.py @@ -1,9 +1,11 @@ import discord -import discordbot.config_discordbot as cfg -from discordbot.helpers import pagination from gamestonk_terminal.stocks.due_diligence import business_insider_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger +from discordbot.helpers import pagination + async def est_command(ctx, ticker=""): """Displays earning estimates [Business Insider]""" @@ -12,7 +14,7 @@ async def est_command(ctx, ticker=""): # Debug if cfg.DEBUG: - print(f"!stocks.dd.est {ticker}") + logger.debug("!stocks.dd.est %s", ticker) # Check for argument if ticker == "": @@ -33,9 +35,9 @@ async def est_command(ctx, 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()) + logger.debug(df_year_estimates.to_string()) + logger.debug(df_quarter_earnings.to_string()) + logger.debug(df_quarter_revenues.to_string()) # Output data cols = [] diff --git a/discordbot/stocks/due_diligence/pt.py b/discordbot/stocks/due_diligence/pt.py index 25da2da3180..24bdd9f43ab 100644 --- a/discordbot/stocks/due_diligence/pt.py +++ b/discordbot/stocks/due_diligence/pt.py @@ -1,15 +1,16 @@ import os from datetime import datetime, timedelta + import discord from matplotlib import pyplot as plt -import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur -import discordbot.helpers from gamestonk_terminal.config_plot import PLOT_DPI - from gamestonk_terminal.stocks.due_diligence import business_insider_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_imgur, logger +import discordbot.helpers + async def pt_command(ctx, ticker="", raw="", start=""): """Displays price targets [Business Insider]""" @@ -17,7 +18,7 @@ async def pt_command(ctx, ticker="", raw="", start=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.dd.pt {ticker}") + logger.debug("!stocks.dd.pt %s", ticker) # Check for argument if ticker == "": @@ -82,7 +83,7 @@ async def pt_command(ctx, ticker="", raw="", start=""): uploaded_image = gst_imgur.upload_image("ta_pt.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [Business Insider] Price Targets " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/due_diligence/sec.py b/discordbot/stocks/due_diligence/sec.py index e93d42eaca8..f512c7eaaae 100644 --- a/discordbot/stocks/due_diligence/sec.py +++ b/discordbot/stocks/due_diligence/sec.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.stocks.due_diligence import marketwatch_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def sec_command(ctx, ticker=""): """Displays sec filings [Market Watch]""" @@ -10,7 +12,7 @@ async def sec_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.dd.sec {ticker}") + logger.debug("!stocks.dd.sec %s", ticker) if ticker == "": raise Exception("A ticker is required") @@ -22,7 +24,7 @@ async def sec_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(df_financials.to_string()) + logger.debug(df_financials.to_string()) # Output data report = "```" + df_financials.to_string() + "```" diff --git a/discordbot/stocks/due_diligence/supplier.py b/discordbot/stocks/due_diligence/supplier.py index bf1b56b0b6a..66b53abdb7e 100644 --- a/discordbot/stocks/due_diligence/supplier.py +++ b/discordbot/stocks/due_diligence/supplier.py @@ -1,8 +1,10 @@ import discord -import discordbot.config_discordbot as cfg from gamestonk_terminal.stocks.due_diligence import csimarket_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def supplier_command(ctx, ticker=""): """Displays suppliers of the company [CSIMarket]""" @@ -10,7 +12,7 @@ async def supplier_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.dd.supplier {ticker}") + logger.debug("!stocks.dd.supplier %s", ticker) if ticker == "": raise Exception("A ticker is required") @@ -22,7 +24,7 @@ async def supplier_command(ctx, ticker=""): # Debug user output if cfg.DEBUG: - print(tickers) + logger.debug(tickers) # Output data embed = discord.Embed( diff --git a/discordbot/stocks/government/contracts.py b/discordbot/stocks/government/contracts.py index 051473fa132..2e3570f22f9 100644 --- a/discordbot/stocks/government/contracts.py +++ b/discordbot/stocks/government/contracts.py @@ -1,14 +1,15 @@ import os + import discord -from matplotlib import pyplot as plt import pandas as pd +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def contracts_command(ctx, ticker="", past_transaction_days="", raw=""): @@ -16,7 +17,9 @@ async def contracts_command(ctx, ticker="", past_transaction_days="", raw=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.contracts {ticker} {past_transaction_days} {raw}") + logger.debug( + "!stocks.gov.contracts %s %s %s", ticker, past_transaction_days, raw + ) if past_transaction_days == "": past_transaction_days = 10 @@ -65,7 +68,7 @@ async def contracts_command(ctx, ticker="", past_transaction_days="", raw=""): uploaded_image = gst_imgur.upload_image("gov_contracts.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = f"Stocks: [quiverquant.com] Contracts by {ticker}" if raw: description = df_contracts.to_string() diff --git a/discordbot/stocks/government/gov_menu.py b/discordbot/stocks/government/gov_menu.py index 4e1ddb557df..b13a8afba47 100644 --- a/discordbot/stocks/government/gov_menu.py +++ b/discordbot/stocks/government/gov_menu.py @@ -1,9 +1,8 @@ import asyncio import discord + import discordbot.config_discordbot as cfg - -from discordbot.run_discordbot import gst_bot - +from discordbot.run_discordbot import gst_bot, logger from discordbot.stocks.government.lasttrades import lasttrades_command from discordbot.stocks.government.topbuys import topbuys_command from discordbot.stocks.government.topsells import topsells_command @@ -75,6 +74,7 @@ class GovernmentCommands(discord.ext.commands.Cog): raw: boolean True or false """ + logger.info("stocks.gov.topbuys") await topbuys_command(ctx, gov_type, past_transactions_months, num, raw) @discord.ext.commands.command( @@ -102,6 +102,7 @@ class GovernmentCommands(discord.ext.commands.Cog): raw: boolean True or false """ + logger.info("stocks.gov.topsells") await topsells_command(ctx, gov_type, past_transactions_months, num, raw) @discord.ext.commands.command( @@ -120,6 +121,7 @@ class GovernmentCommands(discord.ext.commands.Cog): num: int Number of contracts """ + logger.info("stocks.gov.lastcontracts") await lastcontracts_command(ctx, past_transactions_days, num) @discord.ext.commands.command( @@ -138,6 +140,7 @@ class GovernmentCommands(discord.ext.commands.Cog): num: int Number of contracts """ + logger.info("stocks.gov.qtrcontracts") await qtrcontracts_command(ctx, num, analysis) @discord.ext.commands.command( @@ -154,6 +157,7 @@ class GovernmentCommands(discord.ext.commands.Cog): raw: boolean True or false """ + logger.info("stocks.gov.toplobbying") await toplobbying_command(ctx, num, raw) @discord.ext.commands.command( @@ -181,6 +185,7 @@ class GovernmentCommands(discord.ext.commands.Cog): raw: boolean True or false """ + logger.info("stocks.gov.gtrades") await gtrades_command(ctx, ticker, gov_type, past_transactions_months, raw) @discord.ext.commands.command( @@ -205,6 +210,7 @@ class GovernmentCommands(discord.ext.commands.Cog): raw: boolean True or false """ + logger.info("stocks.gov.contracts") await contracts_command(ctx, ticker, past_transaction_days, raw) @discord.ext.commands.command( @@ -219,6 +225,7 @@ class GovernmentCommands(discord.ext.commands.Cog): ticker: str ticker, -h or help """ + logger.info("stocks.gov.histcont") await histcont_command(ctx, ticker) @discord.ext.commands.command( @@ -235,6 +242,7 @@ class GovernmentCommands(discord.ext.commands.Cog): num: int Number of events """ + logger.info("stocks.gov.lobbying") await lobbying_command(ctx, ticker, num) @discord.ext.commands.command( @@ -252,9 +260,7 @@ class GovernmentCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the gov context. The user can then select a reaction to trigger a command. """ - - if cfg.DEBUG: - print(f"\n!stocks.gov {ticker}") + logger.info("!stocks.gov %s", ticker) text = ( "0️⃣ !stocks.gov.lasttrades " @@ -305,44 +311,34 @@ class GovernmentCommands(discord.ext.commands.Cog): "reaction_add", timeout=cfg.MENU_TIMEOUT, check=check ) if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("Reaction selected: 0") await lasttrades_command(ctx) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("Reaction selected: 1") await topbuys_command(ctx) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("Reaction selected: 2") await topsells_command(ctx) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("Reaction selected: 3") await lastcontracts_command(ctx) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("Reaction selected: 4") await qtrcontracts_command(ctx) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("Reaction selected: 5") await toplobbying_command(ctx, ticker) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("Reaction selected: 6") await gtrades_command(ctx, ticker) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("Reaction selected: 7") await contracts_command(ctx, ticker) elif reaction.emoji == "8️⃣": - if cfg.DEBUG: - print("Reaction selected: 8") + logger.info("Reaction selected: 8") await histcont_command(ctx, ticker) elif reaction.emoji == "9️⃣": - if cfg.DEBUG: - print("Reaction selected: 9") + logger.info("Reaction selected: 9") await lobbying_command(ctx, ticker) for emoji in emoji_list: @@ -351,15 +347,16 @@ class GovernmentCommands(discord.ext.commands.Cog): except asyncio.TimeoutError: for emoji in emoji_list: await msg.remove_reaction(emoji, ctx.bot.user) - embed = discord.Embed( - description="Error timeout - you snooze you lose! 😋", - colour=cfg.COLOR, - title="TIMEOUT Stocks: Government (GOV) Menu", - ).set_author( - name=cfg.AUTHOR_NAME, - icon_url=cfg.AUTHOR_ICON_URL, - ) - await ctx.send(embed=embed) + if cfg.DEBUG: + embed = discord.Embed( + description="Error timeout - you snooze you lose! 😋", + colour=cfg.COLOR, + title="TIMEOUT Stocks: Government (GOV) Menu", + ).set_author( + name=cfg.AUTHOR_NAME, + icon_url=cfg.AUTHOR_ICON_URL, + ) + await ctx.send(embed=embed) def setup(bot: discord.ext.commands.Bot): diff --git a/discordbot/stocks/government/gtrades.py b/discordbot/stocks/government/gtrades.py index 20b767ca33c..0839c6c981c 100644 --- a/discordbot/stocks/government/gtrades.py +++ b/discordbot/stocks/government/gtrades.py @@ -1,16 +1,17 @@ import os from datetime import datetime, timedelta + import discord -from matplotlib import pyplot as plt -import matplotlib.dates as mdates import pandas as pd +import matplotlib.dates as mdates +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def gtrades_command( @@ -20,8 +21,12 @@ async def gtrades_command( try: # Debug user input if cfg.DEBUG: - print( - f"!stocks.gov.gtrades {ticker} {gov_type} {past_transactions_months} {raw}" + logger.debug( + "!stocks.gov.gtrades %s %s %s %s", + ticker, + gov_type, + past_transactions_months, + raw, ) if past_transactions_months == "": @@ -67,7 +72,7 @@ async def gtrades_command( df_gov = df_gov[df_gov["TransactionDate"] > start_date] if df_gov.empty: - print(f"No recent {gov_type} trading data found\n") + logger.debug("No recent %s trading data found", gov_type) return df_gov["min"] = df_gov["Range"].apply( @@ -120,7 +125,7 @@ async def gtrades_command( uploaded_image = gst_imgur.upload_image("gov_gtrades.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [quiverquant.com] Government Trades" if raw: description = df_gov.to_string() diff --git a/discordbot/stocks/government/histcont.py b/discordbot/stocks/government/histcont.py index 948051a3da3..72b5c12f6d0 100644 --- a/discordbot/stocks/government/histcont.py +++ b/discordbot/stocks/government/histcont.py @@ -1,14 +1,15 @@ import os + import discord -from matplotlib import pyplot as plt import numpy as np +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def histcont_command(ctx, ticker=""): @@ -16,7 +17,7 @@ async def histcont_command(ctx, ticker=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.histcont {ticker}") + logger.debug("!stocks.gov.histcont %s", ticker) if ticker == "": raise Exception("A ticker is required") @@ -27,7 +28,7 @@ async def histcont_command(ctx, ticker=""): ) if df_contracts.empty: - print("No quarterly government contracts found\n") + logger.debug("No quarterly government contracts found") return # Output Data @@ -56,7 +57,7 @@ async def histcont_command(ctx, ticker=""): uploaded_image = gst_imgur.upload_image("gov_histcont.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Historical Quarterly Government Contract " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/government/lastcontracts.py b/discordbot/stocks/government/lastcontracts.py index 99d1f213c17..8eded79650f 100644 --- a/discordbot/stocks/government/lastcontracts.py +++ b/discordbot/stocks/government/lastcontracts.py @@ -2,7 +2,9 @@ import discord import pandas as pd from gamestonk_terminal.stocks.government import quiverquant_model + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination @@ -11,7 +13,7 @@ async def lastcontracts_command(ctx, past_transactions_days="", num=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.lastcontracts {past_transactions_days} {num}") + logger.debug("!stocks.gov.lastcontracts %s %s", past_transactions_days, num) if past_transactions_days == "": past_transactions_days = 2 @@ -30,7 +32,7 @@ async def lastcontracts_command(ctx, past_transactions_days="", num=""): df_contracts = quiverquant_model.get_government_trading("contracts") if df_contracts.empty: - print("No government contracts found\n") + logger.debug("No government contracts found") return df_contracts.sort_values("Date", ascending=False) diff --git a/discordbot/stocks/government/lasttrades.py b/discordbot/stocks/government/lasttrades.py index 3ad87839447..d5ca07c8fc7 100644 --- a/discordbot/stocks/government/lasttrades.py +++ b/discordbot/stocks/government/lasttrades.py @@ -1,7 +1,9 @@ import discord from gamestonk_terminal.stocks.government import quiverquant_model + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination @@ -12,8 +14,11 @@ async def lasttrades_command( try: # Debug user input if cfg.DEBUG: - print( - f"!stocks.gov.lasttrades {gov_type} {past_transactions_days} {representative}" + logger.debug( + "!stocks.gov.lasttrades %s %s %s", + gov_type, + past_transactions_days, + representative, ) if past_transactions_days == "": diff --git a/discordbot/stocks/government/lobbying.py b/discordbot/stocks/government/lobbying.py index 9e4e9a11ce0..18a89cf75ca 100644 --- a/discordbot/stocks/government/lobbying.py +++ b/discordbot/stocks/government/lobbying.py @@ -1,7 +1,9 @@ import discord from gamestonk_terminal.stocks.government import quiverquant_model + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination @@ -11,7 +13,7 @@ async def lobbying_command(ctx, ticker="", num=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.lobbying {ticker}") + logger.debug("!stocks.gov.lobbying %s", ticker) if ticker == "": raise Exception("A ticker is required") @@ -29,7 +31,7 @@ async def lobbying_command(ctx, ticker="", num=""): ) if df_lobbying.empty: - print("No corporate lobbying found\n") + logger.debug("No corporate lobbying found") return # Output Data diff --git a/discordbot/stocks/government/qtrcontracts.py b/discordbot/stocks/government/qtrcontracts.py index 43b6ccbdd02..38f5aa8f2ed 100644 --- a/discordbot/stocks/government/qtrcontracts.py +++ b/discordbot/stocks/government/qtrcontracts.py @@ -1,15 +1,16 @@ import os + import discord +import numpy as np from matplotlib import pyplot as plt from tabulate import tabulate -import numpy as np from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def qtrcontracts_command(ctx, num="", analysis=""): @@ -17,7 +18,7 @@ async def qtrcontracts_command(ctx, num="", analysis=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.qtrcontracts {num} {analysis}") + logger.debug("!stocks.gov.qtrcontracts %s %s", num, analysis) if num == "": num = 20 @@ -96,7 +97,7 @@ async def qtrcontracts_command(ctx, num="", analysis=""): ) image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [quiverquant.com] Government contracts" embed = discord.Embed( title=title, description=description, colour=cfg.COLOR diff --git a/discordbot/stocks/government/topbuys.py b/discordbot/stocks/government/topbuys.py index d051f5da5f9..93e9dfd621d 100644 --- a/discordbot/stocks/government/topbuys.py +++ b/discordbot/stocks/government/topbuys.py @@ -1,15 +1,16 @@ import os from datetime import datetime, timedelta + import discord -from matplotlib import pyplot as plt import pandas as pd +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def topbuys_command( @@ -19,8 +20,12 @@ async def topbuys_command( try: # Debug user input if cfg.DEBUG: - print( - f"!stocks.gov.topbuys {gov_type} {past_transactions_months} {num} {raw}" + logger.debug( + "!stocks.gov.topbuys %s %s %s %s", + gov_type, + past_transactions_months, + num, + raw, ) if past_transactions_months == "": @@ -58,7 +63,7 @@ async def topbuys_command( df_gov = quiverquant_model.get_government_trading(gov_type) if df_gov.empty: - print(f"No {gov_type} trading data found\n") + logger.debug("No %s trading data found", gov_type) return df_gov = df_gov.sort_values("TransactionDate", ascending=False) @@ -121,7 +126,7 @@ async def topbuys_command( uploaded_image = gst_imgur.upload_image("gov_topbuys.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = f"Stocks: [quiverquant.com] Top purchases for {gov_type.upper()}" if raw: embed = discord.Embed( diff --git a/discordbot/stocks/government/toplobbying.py b/discordbot/stocks/government/toplobbying.py index ec0b500e464..124cad37a9f 100644 --- a/discordbot/stocks/government/toplobbying.py +++ b/discordbot/stocks/government/toplobbying.py @@ -1,14 +1,15 @@ import os + import discord -from matplotlib import pyplot as plt import pandas as pd +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def toplobbying_command(ctx, num="", raw=""): @@ -16,7 +17,7 @@ async def toplobbying_command(ctx, num="", raw=""): try: # Debug user input if cfg.DEBUG: - print(f"!stocks.gov.toplobbying {num} {raw}") + logger.debug("!stocks.gov.toplobbying %s %s", num, raw) if num == "": num = 10 @@ -56,7 +57,7 @@ async def toplobbying_command(ctx, num="", raw=""): uploaded_image = gst_imgur.upload_image("ta_toplobbying.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [quiverquant.com] Top Lobbying Firms" if raw: description = lobbying_by_ticker.head(num).to_string() diff --git a/discordbot/stocks/government/topsells.py b/discordbot/stocks/government/topsells.py index 5063a5fd7f9..884d74c8548 100644 --- a/discordbot/stocks/government/topsells.py +++ b/discordbot/stocks/government/topsells.py @@ -1,15 +1,16 @@ import os from datetime import datetime, timedelta + import discord -from matplotlib import pyplot as plt import pandas as pd +from matplotlib import pyplot as plt from gamestonk_terminal.config_plot import PLOT_DPI -from gamestonk_terminal.stocks.government import quiverquant_model from gamestonk_terminal.helper_funcs import plot_autoscale +from gamestonk_terminal.stocks.government import quiverquant_model import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def topsells_command( @@ -19,8 +20,12 @@ async def topsells_command( try: # Debug user input if cfg.DEBUG: - print( - f"!stocks.gov.topsells {gov_type} {past_transactions_months} {num} {raw}" + logger.debug( + "!stocks.gov.topsells %s %s %s %s", + gov_type, + past_transactions_months, + num, + raw, ) if past_transactions_months == "": @@ -134,7 +139,7 @@ async def topsells_command( uploaded_image = gst_imgur.upload_image("gov_topsells.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = f"Stocks: [quiverquant.com] Top sells for {gov_type.upper()}" if raw: embed = discord.Embed( diff --git a/discordbot/stocks/options/calls.py b/discordbot/stocks/options/calls.py index e50b5748e8a..9e823e39f25 100644 --- a/discordbot/stocks/options/calls.py +++ b/discordbot/stocks/options/calls.py @@ -3,6 +3,7 @@ import yfinance as yf from tabulate import tabulate import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination @@ -11,7 +12,7 @@ async def calls_command(ctx, ticker: str = "", expiration_date: str = ""): try: # Debug if cfg.DEBUG: - print(f"!stocks.opt.calls {ticker.upper()} {expiration_date}") + logger.debug("!stocks.opt.calls %s %s", ticker, expiration_date) # Check for argument if ticker == "": diff --git a/discordbot/stocks/options/expirations.py b/discordbot/stocks/options/expirations.py index f0485eb4c7e..79958bb4d21 100644 --- a/discordbot/stocks/options/expirations.py +++ b/discordbot/stocks/options/expirations.py @@ -3,6 +3,7 @@ import pandas as pd import yfinance as yf import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger async def expirations_command(ctx, ticker: str = ""): @@ -10,7 +11,7 @@ async def expirations_command(ctx, ticker: str = ""): try: # Debug if cfg.DEBUG: - print(f"!stocks.opt.exp {ticker.upper()}") + logger.debug("!stocks.opt.exp %s", ticker) # Check for argument if ticker == "": diff --git a/discordbot/stocks/options/hist.py b/discordbot/stocks/options/hist.py index 2f563641811..4c132649d04 100644 --- a/discordbot/stocks/options/hist.py +++ b/discordbot/stocks/options/hist.py @@ -1,11 +1,14 @@ -import os import asyncio -import discord +import os +import discord import mplfinance as mpf + from gamestonk_terminal.config_terminal import TRADIER_TOKEN from gamestonk_terminal.stocks.options import tradier_model + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger async def hist_command( @@ -35,10 +38,12 @@ async def hist_command( # Debug if cfg.DEBUG: - print(f"!stocks.opt.hist {ticker} {strike} {put} {expiry}") + logger.debug( + "!stocks.opt.hist %s %s %s %s", ticker, strike, put, expiry + ) error = "" - if TRADIER_TOKEN == "REPLACE_ME": + if TRADIER_TOKEN == "REPLACE_ME": # nosec raise Exception("Tradier Token is required") # Check for argument @@ -94,7 +99,7 @@ async def hist_command( image = discord.File(imagefile) if cfg.DEBUG: - print(f"Image: {imagefile}") + logger.debug("Image: %s", imagefile) title = f"{ticker.upper()} {strike} {op_type} expiring {expiry} Historical" embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_image(url="attachment://opt_hist.png") diff --git a/discordbot/stocks/options/iv.py b/discordbot/stocks/options/iv.py index 89f825b9655..d43d5634861 100644 --- a/discordbot/stocks/options/iv.py +++ b/discordbot/stocks/options/iv.py @@ -1,18 +1,19 @@ import discord from tabulate import tabulate -import discordbot.config_discordbot as cfg from gamestonk_terminal.stocks.options import barchart_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def iv_command(ctx, ticker: str = None): """Options IV""" try: - # Debug if cfg.DEBUG: - print(f"!stocks.opt.iv {ticker}") + logger.debug("!stocks.opt.iv %s", ticker) # Check for argument if ticker is None: diff --git a/discordbot/stocks/options/oi.py b/discordbot/stocks/options/oi.py index 51b2021cf66..8cc40e0a736 100644 --- a/discordbot/stocks/options/oi.py +++ b/discordbot/stocks/options/oi.py @@ -1,14 +1,16 @@ import os import discord -import matplotlib.pyplot as plt import pandas as pd +import matplotlib.pyplot as plt -import discordbot.config_discordbot as cfg from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.helper_funcs import plot_autoscale from gamestonk_terminal.stocks.options import op_helpers, yfinance_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def oi_command( ctx, @@ -20,10 +22,9 @@ async def oi_command( """Options OI""" try: - # Debug if cfg.DEBUG: - print(f"!stocks.opt.oi {ticker} {expiry} {min_sp} {max_sp}") + logger.debug("!stocks.opt.oi %s %s %s %s", ticker, expiry, min_sp, max_sp) # Check for argument if ticker is None: @@ -97,7 +98,7 @@ async def oi_command( image = discord.File(imagefile) if cfg.DEBUG: - print(f"Image {imagefile}") + logger.debug("Image %s", imagefile) title = f"Open Interest for {ticker.upper()} expiring {expiry}" embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_image(url="attachment://opt_oi.png") diff --git a/discordbot/stocks/options/opt_cmd.py b/discordbot/stocks/options/opt_cmd.py index daac8cd8fcc..4ef95b32412 100644 --- a/discordbot/stocks/options/opt_cmd.py +++ b/discordbot/stocks/options/opt_cmd.py @@ -1,9 +1,8 @@ import asyncio + import discord - import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_bot - +from discordbot.run_discordbot import gst_bot, logger from discordbot.stocks.options.calls import calls_command from discordbot.stocks.options.expirations import expirations_command from discordbot.stocks.options.hist import hist_command @@ -20,7 +19,7 @@ async def opt_command(ctx, ticker="", expiration="", strike="", put=""): """Options Menu command""" if cfg.DEBUG: - print(f"!stocks.opt {ticker} {expiration} {strike} {put}") + logger.debug("!stocks.opt %s %s %s %s", ticker, expiration, strike, put) if ticker: current = 1 diff --git a/discordbot/stocks/options/options_menu.py b/discordbot/stocks/options/options_menu.py index 2c128a45726..b8e07b6016a 100644 --- a/discordbot/stocks/options/options_menu.py +++ b/discordbot/stocks/options/options_menu.py @@ -1,14 +1,12 @@ import asyncio import discord -import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_bot -from discordbot.reaction_helper import expiry_dates_reaction from gamestonk_terminal.config_terminal import TRADIER_TOKEN from gamestonk_terminal.stocks.options import tradier_model, yfinance_model -# pylint: disable=C0412 - +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import gst_bot, logger +from discordbot.reaction_helper import expiry_dates_reaction from discordbot.stocks.options.calls import calls_command from discordbot.stocks.options.expirations import expirations_command from discordbot.stocks.options.hist import hist_command @@ -35,6 +33,7 @@ class OptionsCommands(discord.ext.commands.Cog): ticker: str ticker, """ + logger.info("stocks.opt.iv") async with ctx.typing(): await asyncio.sleep(0.2) @@ -53,6 +52,7 @@ class OptionsCommands(discord.ext.commands.Cog): ticker: str ticker """ + logger.info("stocks.opt.unu") async with ctx.typing(): await asyncio.sleep(0.2) @@ -67,6 +67,7 @@ class OptionsCommands(discord.ext.commands.Cog): ticker: str Stock ticker """ + logger.info("stocks.opt.exp") await expirations_command(ctx, ticker) @discord.ext.commands.command( @@ -87,12 +88,10 @@ class OptionsCommands(discord.ext.commands.Cog): 0 weeklies, 1+ for weeks out prompts reaction helper if empty """ + logger.info("!stocks.opt.calls %s %s", ticker, expiry) async with ctx.typing(): await asyncio.sleep(0.2) - if cfg.DEBUG: - print(f"!stocks.opt.calls {ticker} {expiry}") - func_cmd = calls_command await expiry_dates_reaction(ctx, ticker, expiry, func_cmd) @@ -115,12 +114,10 @@ class OptionsCommands(discord.ext.commands.Cog): 0 weeklies, 1+ for weeks out prompts reaction helper if empty """ + logger.info("!stocks.opt.puts %s %s", ticker, expiry) async with ctx.typing(): await asyncio.sleep(0.2) - if cfg.DEBUG: - print(f"!stocks.opt.puts {ticker} {expiry}") - func_cmd = puts_command await expiry_dates_reaction(ctx, ticker, expiry, func_cmd) @@ -155,12 +152,10 @@ class OptionsCommands(discord.ext.commands.Cog): Sends a message to the discord user with the expiry dates if empty. The user can then select a reaction to trigger the selected date. """ + logger.info("!stocks.opt.oi %s %s %s %s", ticker, expiry, min_sp, max_sp) async with ctx.typing(): await asyncio.sleep(0.2) - if cfg.DEBUG: - print(f"!stocks.opt.oi {ticker} {expiry} {min_sp} {max_sp}") - call_arg = (min_sp, max_sp) func_cmd = oi_command @@ -195,15 +190,12 @@ class OptionsCommands(discord.ext.commands.Cog): Sends a message to the discord user with the expiry dates if empty. The user can then select a reaction to trigger the selected date. """ + logger.info("!stocks.opt.hist %s %s %s %s", ticker, strike, put, expiry) async with ctx.typing(): await asyncio.sleep(0.2) try: - - if cfg.DEBUG: - print(f"!stocks.opt.hist {ticker} {strike} {put} {expiry}") - error = "" - if TRADIER_TOKEN == "REPLACE_ME": + if TRADIER_TOKEN == "REPLACE_ME": # nosec raise Exception("Tradier Token is required") if expiry in ("c", "p"): @@ -236,9 +228,9 @@ class OptionsCommands(discord.ext.commands.Cog): ) except Exception as e: error = str(e) - finally: if error: + logger.error(error) embed = discord.Embed( title="ERROR Options: History", colour=cfg.COLOR, @@ -281,12 +273,10 @@ class OptionsCommands(discord.ext.commands.Cog): Sends a message to the discord user with the expiry dates if empty. The user can then select a reaction to trigger the selected date. """ + logger.info("stocks.opt.vol %s %s %s %s", ticker, expiry, min_sp, max_sp) async with ctx.typing(): await asyncio.sleep(0.2) - if cfg.DEBUG: - print(f"!stocks.opt.vol {ticker} {expiry} {min_sp} {max_sp}") - call_arg = (min_sp, max_sp) func_cmd = vol_command @@ -312,19 +302,17 @@ class OptionsCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the stocks/options context. The user can then select a reaction to trigger a command. """ + logger.info("!stocks.opt %s %s %s %s", ticker, expiration, strike, put) async with ctx.typing(): await asyncio.sleep(0.2) - if TRADIER_TOKEN == "REPLACE_ME": + if TRADIER_TOKEN == "REPLACE_ME": # nosec dates = yfinance_model.option_expirations(ticker) else: dates = tradier_model.option_expirations(ticker) index_dates = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - if cfg.DEBUG: - print(f"!stocks.opt {ticker} {expiration} {strike} {put}") - if not ticker: current = 0 text = ( @@ -402,36 +390,28 @@ class OptionsCommands(discord.ext.commands.Cog): "reaction_add", timeout=cfg.MENU_TIMEOUT, check=check ) if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("Reaction selected: 0") await unu_command(ctx) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("Reaction selected: 1") await expirations_command(ctx, ticker) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("Reaction selected: 2") await iv_command(ctx, ticker) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("Reaction selected: 3") await calls_command(ctx, ticker, expiration) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("Reaction selected: 4") await puts_command(ctx, ticker, expiration) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("Reaction selected: 5") await oi_command(ctx, ticker, expiration) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("Reaction selected: 6") await vol_command(ctx, ticker, expiration) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("Reaction selected: 7") strike = float(strike) await hist_command(ctx, ticker, expiration, strike, put) diff --git a/discordbot/stocks/options/puts.py b/discordbot/stocks/options/puts.py index e9356570b27..032554cf0dc 100644 --- a/discordbot/stocks/options/puts.py +++ b/discordbot/stocks/options/puts.py @@ -3,6 +3,7 @@ import yfinance as yf from tabulate import tabulate import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination @@ -11,7 +12,7 @@ async def puts_command(ctx, ticker: str = "", expiration_date: str = ""): try: # Debug if cfg.DEBUG: - print(f"!stocks.opt.puts {ticker.upper()} {expiration_date}") + logger.debug("!stocks.opt.puts %s %s", ticker, expiration_date) # Check for argument if ticker == "": diff --git a/discordbot/stocks/options/unu.py b/discordbot/stocks/options/unu.py index e1ebe813dec..acb18106e21 100644 --- a/discordbot/stocks/options/unu.py +++ b/discordbot/stocks/options/unu.py @@ -4,9 +4,11 @@ import pandas as pd import requests from tabulate import tabulate -import discordbot.config_discordbot as cfg from gamestonk_terminal.helper_funcs import get_user_agent +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def unu_command(ctx, num: int = None): """Unusual Options""" @@ -14,7 +16,7 @@ async def unu_command(ctx, num: int = None): # Debug if cfg.DEBUG: - print(f"!stocks.opt.unu {num}") + logger.debug("!stocks.opt.unu %s", num) # Check for argument if num is None: @@ -30,7 +32,7 @@ async def unu_command(ctx, num: int = None): ) if r.status_code != 200: - print("Error in fdscanner request") + logger.debug("Error in fdscanner request") return pd.DataFrame(), "request error" data_list.append(r.json()) diff --git a/discordbot/stocks/options/vol.py b/discordbot/stocks/options/vol.py index 5aa346b714a..c63bec835e2 100644 --- a/discordbot/stocks/options/vol.py +++ b/discordbot/stocks/options/vol.py @@ -1,12 +1,15 @@ import os + import discord import matplotlib.pyplot as plt -import discordbot.config_discordbot as cfg from gamestonk_terminal import config_plot as cfp from gamestonk_terminal.helper_funcs import plot_autoscale from gamestonk_terminal.stocks.options import yfinance_model +import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger + async def vol_command( ctx, @@ -21,7 +24,7 @@ async def vol_command( # Debug if cfg.DEBUG: - print(f"!stocks.opt.vol {ticker} {expiry} {min_sp} {max_sp}") + logger.debug("!stocks.opt.vol %s %s %s %s", ticker, expiry, min_sp, max_sp) # Check for argument if ticker is None: @@ -87,7 +90,7 @@ async def vol_command( image = discord.File(imagefile) if cfg.DEBUG: - print(f"Image: {imagefile}") + logger.debug("Image: %s", imagefile) title = f"Volume for {ticker.upper()} expiring {expiry}" embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_image(url="attachment://opt_vol.png") diff --git a/discordbot/stocks/screener/financial.py b/discordbot/stocks/screener/financial.py index 4a8d6a56bac..d0dcf2fe64b 100644 --- a/discordbot/stocks/screener/financial.py +++ b/discordbot/stocks/screener/financial.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -17,7 +20,9 @@ async def financial_command(ctx, preset="template", sort="", limit="5", ascend=" # Debug if cfg.DEBUG: - print(f"!stocks.scr.financial {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.financial %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/screener/historical.py b/discordbot/stocks/screener/historical.py index de3475b34c3..b277f9b63f5 100644 --- a/discordbot/stocks/screener/historical.py +++ b/discordbot/stocks/screener/historical.py @@ -2,6 +2,7 @@ import os import random from datetime import datetime, timedelta import configparser + import discord from matplotlib import pyplot as plt import yfinance as yf @@ -13,6 +14,7 @@ from gamestonk_terminal.stocks.screener import finviz_model from gamestonk_terminal.helper_funcs import plot_autoscale import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.run_discordbot import gst_imgur from discordbot.stocks.screener import screener_options as so @@ -25,7 +27,7 @@ async def historical_command(ctx, signal="", start=""): # Debug user input if cfg.DEBUG: - print(f"!stocks.scr.historical {signal} {start}") + logger.debug("!stocks.scr.historical %s %s", signal, start) # Check for argument if signal == "" or signal not in list(so.d_signals_desc.keys): @@ -75,7 +77,7 @@ async def historical_command(ctx, signal="", start=""): random.shuffle(l_stocks) l_stocks = sorted(l_stocks[:10]) description = description + (", ".join(l_stocks)) - print(description) + logger.debug(description) plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI) @@ -138,7 +140,7 @@ async def historical_command(ctx, signal="", start=""): uploaded_image = gst_imgur.upload_image("scr_historical.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [Yahoo Finance] Historical Screener" embed = discord.Embed(title=title, description=description, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/screener/overview.py b/discordbot/stocks/screener/overview.py index 6b91cbfceca..67335572235 100644 --- a/discordbot/stocks/screener/overview.py +++ b/discordbot/stocks/screener/overview.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -17,7 +20,9 @@ async def overview_command(ctx, preset="template", sort="", limit="5", ascend="F # Debug if cfg.DEBUG: - print(f"!stocks.scr.overview {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.overview %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/screener/ownership.py b/discordbot/stocks/screener/ownership.py index ed1f7147a32..134bfc5b149 100644 --- a/discordbot/stocks/screener/ownership.py +++ b/discordbot/stocks/screener/ownership.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -17,7 +20,9 @@ async def ownership_command(ctx, preset="template", sort="", limit="5", ascend=" # Debug if cfg.DEBUG: - print(f"!stocks.scr.ownership {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.ownership %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/screener/performance.py b/discordbot/stocks/screener/performance.py index 8c89ce8037a..73a0ad7920b 100644 --- a/discordbot/stocks/screener/performance.py +++ b/discordbot/stocks/screener/performance.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -19,7 +22,9 @@ async def performance_command( # Debug if cfg.DEBUG: - print(f"!stocks.scr.performance {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.performance %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/screener/presets_custom.py b/discordbot/stocks/screener/presets_custom.py index 190a30a6d1a..44952faea4a 100644 --- a/discordbot/stocks/screener/presets_custom.py +++ b/discordbot/stocks/screener/presets_custom.py @@ -1,7 +1,7 @@ import discord import discordbot.config_discordbot as cfg - +from discordbot.run_discordbot import logger from discordbot.stocks.screener import screener_options as so @@ -11,7 +11,7 @@ async def presets_custom_command(ctx): # Debug if cfg.DEBUG: - print("!stocks.scr.presets") + logger.debug("!stocks.scr.presets") description = "" for preset in so.presets: diff --git a/discordbot/stocks/screener/presets_default.py b/discordbot/stocks/screener/presets_default.py index 3b5e1fc0794..97711cf97c1 100644 --- a/discordbot/stocks/screener/presets_default.py +++ b/discordbot/stocks/screener/presets_default.py @@ -1,7 +1,7 @@ import discord import discordbot.config_discordbot as cfg - +from discordbot.run_discordbot import logger from discordbot.stocks.screener import screener_options as so @@ -11,7 +11,7 @@ async def presets_default_command(ctx): # Debug if cfg.DEBUG: - print("!stocks.scr.presets") + logger.debug("!stocks.scr.presets") description = "" for signame, sigdesc in so.d_signals_desc.items(): diff --git a/discordbot/stocks/screener/screener_menu.py b/discordbot/stocks/screener/screener_menu.py index d1b8cf5f8ac..33336fba692 100644 --- a/discordbot/stocks/screener/screener_menu.py +++ b/discordbot/stocks/screener/screener_menu.py @@ -2,9 +2,7 @@ import asyncio import discord import discordbot.config_discordbot as cfg - -from discordbot.run_discordbot import gst_bot - +from discordbot.run_discordbot import gst_bot, logger from discordbot.stocks.screener.historical import historical_command from discordbot.stocks.screener.overview import overview_command from discordbot.stocks.screener.presets_custom import presets_custom_command @@ -29,11 +27,13 @@ class ScreenerCommands(discord.ext.commands.Cog): @discord.ext.commands.command(name="stocks.scr.presets_default") async def presets_default(self, ctx: discord.ext.commands.Context): """Displays every available preset""" + logger.info("stocks.scr.presets_default") await presets_default_command(ctx) @discord.ext.commands.command(name="stocks.scr.presets_custom") async def presets_custom(self, ctx: discord.ext.commands.Context): """Displays every available preset""" + logger.info("stocks.scr.presets_custom") await presets_custom_command(ctx) @discord.ext.commands.command( @@ -54,6 +54,7 @@ class ScreenerCommands(discord.ext.commands.Cog): start: Starting date in YYYY-MM-DD format """ + logger.info("stocks.scr.historical") await historical_command(ctx, signal, start) @discord.ext.commands.command( @@ -80,6 +81,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.overview") await overview_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command( @@ -106,6 +108,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.valuation") await valuation_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command( @@ -132,6 +135,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.financial") await financial_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command( @@ -158,6 +162,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.ownership") await ownership_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command( @@ -184,6 +189,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.performance") await performance_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command( @@ -210,6 +216,7 @@ class ScreenerCommands(discord.ext.commands.Cog): ascend: boolean whether it's sorted by ascending order or not. Default: False """ + logger.info("stocks.scr.technical") await technical_command(ctx, preset, sort, limit, ascend) @discord.ext.commands.command(name="stocks.scr") @@ -223,13 +230,11 @@ class ScreenerCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the screener context. The user can then select a reaction to trigger a command. """ + logger.info("!stocks.scr") if preset != "" and preset not in so.all_presets: raise Exception("Invalid preset selected!") - if cfg.DEBUG: - print("!stocks.scr") - if preset: text = ( "0️⃣ !stocks.scr.presets_default\n" @@ -276,40 +281,31 @@ class ScreenerCommands(discord.ext.commands.Cog): "reaction_add", timeout=cfg.MENU_TIMEOUT, check=check ) if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("!stocks.scr. Reaction selected: 0") await presets_default_command(ctx) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("!stocks.scr. Reaction selected: 1") await presets_custom_command(ctx) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("!stocks.scr. Reaction selected: 2") await historical_command(ctx, preset) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("!stocks.scr. Reaction selected: 3") await overview_command(ctx, preset) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("!stocks.scr. Reaction selected: 4") await valuation_command(ctx, preset) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("!stocks.scr. Reaction selected: 5") await financial_command(ctx, preset) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("!stocks.scr. Reaction selected: 6") await ownership_command(ctx, preset) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("!stocks.scr. Reaction selected: 7") await performance_command(ctx, preset) elif reaction.emoji == "8️⃣": - if cfg.DEBUG: - print("Reaction selected: 8") + logger.info("!stocks.scr. Reaction selected: 8") await technical_command(ctx, preset) for emoji in emoji_list: diff --git a/discordbot/stocks/screener/technical.py b/discordbot/stocks/screener/technical.py index 78da2eff936..2a41dcd006a 100644 --- a/discordbot/stocks/screener/technical.py +++ b/discordbot/stocks/screener/technical.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -17,7 +20,9 @@ async def technical_command(ctx, preset="template", sort="", limit="5", ascend=" # Debug if cfg.DEBUG: - print(f"!stocks.scr.technical {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.technical %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/screener/valuation.py b/discordbot/stocks/screener/valuation.py index 0366bea928f..081b27568e2 100644 --- a/discordbot/stocks/screener/valuation.py +++ b/discordbot/stocks/screener/valuation.py @@ -1,9 +1,12 @@ import difflib + import discord import pandas as pd from gamestonk_terminal.stocks.screener.finviz_model import get_screener_data + import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger from discordbot.helpers import pagination from discordbot.stocks.screener import screener_options as so @@ -17,7 +20,9 @@ async def valuation_command(ctx, preset="template", sort="", limit="5", ascend=" # Debug if cfg.DEBUG: - print(f"!stocks.scr.valuation {preset} {sort} {limit} {ascend}") + logger.debug( + "!stocks.scr.valuation %s %s %s %s", preset, sort, limit, ascend + ) # Check for argument if not limit.lstrip("-").isnumeric(): diff --git a/discordbot/stocks/technical_analysis/ad.py b/discordbot/stocks/technical_analysis/ad.py index db26413e858..77b9654eba8 100644 --- a/discordbot/stocks/technical_analysis/ad.py +++ b/discordbot/stocks/technical_analysis/ad.py @@ -1,14 +1,15 @@ import os from datetime import datetime, timedelta + import discord from matplotlib import pyplot as plt -from gamestonk_terminal.helper_funcs import plot_autoscale from gamestonk_terminal.common.technical_analysis import volume_model from gamestonk_terminal.config_plot import PLOT_DPI +from gamestonk_terminal.helper_funcs import plot_autoscale import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +20,7 @@ async def ad_command(ctx, ticker="", is_open="False", start="", end=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.ad {ticker} {is_open} {start} {end}") + logger.debug("!stocks.ta.ad %s %s %s %s", ticker, is_open, start, end) # Check for argument if ticker == "": @@ -103,7 +104,7 @@ async def ad_command(ctx, ticker="", is_open="False", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_ad.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Accumulation/Distribution Line " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/adosc.py b/discordbot/stocks/technical_analysis/adosc.py index 4a5ceaf0425..3c506ba1a6f 100644 --- a/discordbot/stocks/technical_analysis/adosc.py +++ b/discordbot/stocks/technical_analysis/adosc.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import volume_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -18,10 +18,18 @@ async def adosc_command( """Displays chart with chaikin oscillator [Yahoo Finance]""" try: - # Debug if cfg.DEBUG: - print(f"!stocks.ta.adosc {ticker} {is_open} {fast} {slow} {start} {end}") + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.adosc %s %s %s %s %s", + ticker, + is_open, + fast, + slow, + start, + end, + ) # Check for argument if ticker == "": @@ -113,7 +121,7 @@ async def adosc_command( uploaded_image = gst_imgur.upload_image("ta_adosc.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Accumulation/Distribution Oscillator " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/adx.py b/discordbot/stocks/technical_analysis/adx.py index ffec07fb747..36d5325f724 100644 --- a/discordbot/stocks/technical_analysis/adx.py +++ b/discordbot/stocks/technical_analysis/adx.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import trend_indicators_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,7 +21,16 @@ async def adx_command( # Debug if cfg.DEBUG: - print(f"!stocks.ta.adx {ticker} {length} {scalar} {drift} {start} {end}") + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.adx %s %s %s %s %s", + ticker, + length, + scalar, + drift, + start, + end, + ) # Check for argument if ticker == "": @@ -92,7 +101,7 @@ async def adx_command( uploaded_image = gst_imgur.upload_image("ta_adx.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Average-Directional-Movement-Index " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/aroon.py b/discordbot/stocks/technical_analysis/aroon.py index bd7f551ec86..829f1cdabbc 100644 --- a/discordbot/stocks/technical_analysis/aroon.py +++ b/discordbot/stocks/technical_analysis/aroon.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import trend_indicators_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def aroon_command(ctx, ticker="", length="25", scalar="100", start="", end # Debug if cfg.DEBUG: - print(f"!stocks.ta.aroon {ticker} {length} {scalar} {start} {end}") + logger.debug( + "!stocks.ta.aroon %s %s %s %s %s", + ticker, + length, + scalar, + start, + end, + ) # Check for argument if ticker == "": @@ -88,7 +95,7 @@ async def aroon_command(ctx, ticker="", length="25", scalar="100", start="", end uploaded_image = gst_imgur.upload_image("ta_aroon.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Aroon-Indicator " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/bbands.py b/discordbot/stocks/technical_analysis/bbands.py index c0df5a6962c..5161864ce04 100644 --- a/discordbot/stocks/technical_analysis/bbands.py +++ b/discordbot/stocks/technical_analysis/bbands.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import volatility_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,7 +21,16 @@ async def bbands_command( # Debug if cfg.DEBUG: - print(f"!stocks.ta.bbands {ticker} {length} {n_std} {mamode} {start} {end}") + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.bbands %s %s %s %s %s %s", + ticker, + length, + n_std, + mamode, + start, + end, + ) # Check for argument possible_ma = [ @@ -105,7 +114,7 @@ async def bbands_command( uploaded_image = gst_imgur.upload_image("ta_bbands.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Bollinger-Bands " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/cci.py b/discordbot/stocks/technical_analysis/cci.py index 90c2bd5f3d9..b2e2bdf04c3 100644 --- a/discordbot/stocks/technical_analysis/cci.py +++ b/discordbot/stocks/technical_analysis/cci.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def cci_command(ctx, ticker="", length="14", scalar="0.015", start="", end # Debug if cfg.DEBUG: - print(f"!stocks.ta.cci {ticker} {length} {scalar} {start} {end}") + logger.debug( + "!stocks.ta.cci %s %s %s %s %s", + ticker, + length, + scalar, + start, + end, + ) # Check for argument if ticker == "": @@ -80,7 +87,7 @@ async def cci_command(ctx, ticker="", length="14", scalar="0.015", start="", end uploaded_image = gst_imgur.upload_image("ta_cci.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Commodity-Channel-Index " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/cg.py b/discordbot/stocks/technical_analysis/cg.py index 99b8f7cba83..49e1ff83f62 100644 --- a/discordbot/stocks/technical_analysis/cg.py +++ b/discordbot/stocks/technical_analysis/cg.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -20,7 +20,13 @@ async def cg_command(ctx, ticker="", length="14", start="", end=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.cg {ticker} {length} {start} {end}") + logger.debug( + "!stocks.ta.cg %s %s %s %s", + ticker, + length, + start, + end, + ) # Check for argument if ticker == "": @@ -76,7 +82,7 @@ async def cg_command(ctx, ticker="", length="14", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_cg.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Center-of-Gravity " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/donchian.py b/discordbot/stocks/technical_analysis/donchian.py index 5697ceefa07..341244afb37 100644 --- a/discordbot/stocks/technical_analysis/donchian.py +++ b/discordbot/stocks/technical_analysis/donchian.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import volatility_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,8 +21,13 @@ async def donchian_command( # Debug if cfg.DEBUG: - print( - f"!stocks.ta.donchian {ticker} {upper_length} {lower_length} {start} {end}" + logger.debug( + "!stocks.ta.donchian %s %s %s %s %s", + ticker, + upper_length, + lower_length, + start, + end, ) # Check for argument @@ -86,7 +91,7 @@ async def donchian_command( uploaded_image = gst_imgur.upload_image("ta_donchian.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Donchian-Channels " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/ema.py b/discordbot/stocks/technical_analysis/ema.py index 31d5e5f2160..3a50cb702a6 100644 --- a/discordbot/stocks/technical_analysis/ema.py +++ b/discordbot/stocks/technical_analysis/ema.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import overlap_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def ema_command(ctx, ticker="", window="", offset="", start="", end=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.ta.ema {ticker} {window} {offset} {start} {end}") + logger.debug( + "!stocks.ta.ema %s %s %s %s %s", + ticker, + window, + offset, + start, + end, + ) # Check for argument if ticker == "": @@ -101,7 +108,7 @@ async def ema_command(ctx, ticker="", window="", offset="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_ema.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Exponential-Moving-Average " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/fib.py b/discordbot/stocks/technical_analysis/fib.py index 472c8c0016f..c56d32e6686 100644 --- a/discordbot/stocks/technical_analysis/fib.py +++ b/discordbot/stocks/technical_analysis/fib.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import custom_indicators_model from gamestonk_terminal import config_plot as cfp import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,12 @@ async def fib_command(ctx, ticker="", start="", end=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.fib {ticker} {start} {end}") + logger.debug( + "!stocks.ta.fib %s %s %s", + ticker, + start, + end, + ) # Check for argument if ticker == "": @@ -81,7 +86,7 @@ async def fib_command(ctx, ticker="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_fib.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Fibonacci-Retracement-Levels " + ticker str_df_fib = "```" + df_fib.to_string(index=False) + "```" embed = discord.Embed(title=title, colour=cfg.COLOR, description=str_df_fib) diff --git a/discordbot/stocks/technical_analysis/fisher.py b/discordbot/stocks/technical_analysis/fisher.py index 82a9f1bc0e1..38c1692fd6c 100644 --- a/discordbot/stocks/technical_analysis/fisher.py +++ b/discordbot/stocks/technical_analysis/fisher.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,7 @@ async def fisher_command(ctx, ticker="", length="14", start="", end=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.fisher {ticker} {length} {start} {end}") + logger.debug("!stocks.ta.fisher %s %s %s %s", ticker, length, start, end) # Check for argument if ticker == "": @@ -97,7 +97,7 @@ async def fisher_command(ctx, ticker="", length="14", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_fisher.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Fisher-Transform " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/hma.py b/discordbot/stocks/technical_analysis/hma.py index e0adc0975c1..06df4bc1f7a 100644 --- a/discordbot/stocks/technical_analysis/hma.py +++ b/discordbot/stocks/technical_analysis/hma.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import overlap_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def hma_command(ctx, ticker="", window="", offset="", start="", end=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.ta.hma {ticker} {window} {offset} {start} {end}") + logger.debug( + "!stocks.ta.hma %s %s %s %s %s", + ticker, + window, + offset, + start, + end, + ) # Check for argument if ticker == "": @@ -100,7 +107,7 @@ async def hma_command(ctx, ticker="", window="", offset="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_hma.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Hull-Moving-Average " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/kc.py b/discordbot/stocks/technical_analysis/kc.py index 15b5cf199e2..c1c5964d977 100644 --- a/discordbot/stocks/technical_analysis/kc.py +++ b/discordbot/stocks/technical_analysis/kc.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import volatility_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,8 +21,16 @@ async def kc_command( # Debug if cfg.DEBUG: - print( - f"!stocks.ta.kc {ticker} {length} {scalar} {mamode} {offset} {start} {end}" + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.kc %s %s %s %s %s %s %s", + ticker, + length, + scalar, + mamode, + offset, + start, + end, ) # Check for argument @@ -94,7 +102,7 @@ async def kc_command( uploaded_image = gst_imgur.upload_image("ta_kc.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Keltner-Channel " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/macd.py b/discordbot/stocks/technical_analysis/macd.py index f7cf23ed01a..9d5a83f8c7a 100644 --- a/discordbot/stocks/technical_analysis/macd.py +++ b/discordbot/stocks/technical_analysis/macd.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,7 +21,16 @@ async def macd_command( # Debug if cfg.DEBUG: - print(f"!stocks.ta.macd {ticker} {fast} {slow} {signal} {start} {end}") + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.macd %s %s %s %s %s %s", + ticker, + fast, + slow, + signal, + start, + end, + ) # Check for argument if ticker == "": @@ -88,7 +97,7 @@ async def macd_command( uploaded_image = gst_imgur.upload_image("ta_cci.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Moving-Average-Convergence-Divergence " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/obv.py b/discordbot/stocks/technical_analysis/obv.py index 10661620f37..05901d41558 100644 --- a/discordbot/stocks/technical_analysis/obv.py +++ b/discordbot/stocks/technical_analysis/obv.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import volume_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,12 @@ async def obv_command(ctx, ticker="", start="", end=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.obv {ticker} {start} {end}") + logger.debug( + "!stocks.ta.obv %s %s %s", + ticker, + start, + end, + ) # Check for argument if ticker == "": @@ -99,7 +104,7 @@ async def obv_command(ctx, ticker="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_obv.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: On-Balance-Volume " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/recom.py b/discordbot/stocks/technical_analysis/recom.py index ec957b140dd..30ad0d39c48 100644 --- a/discordbot/stocks/technical_analysis/recom.py +++ b/discordbot/stocks/technical_analysis/recom.py @@ -3,6 +3,7 @@ import discord from gamestonk_terminal.stocks.technical_analysis import tradingview_model import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger async def recom_command(ctx, ticker=""): @@ -12,7 +13,7 @@ async def recom_command(ctx, ticker=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.recom {ticker}") + logger.debug("!stocks.ta.recom %s", ticker) # Check for argument if ticker == "": diff --git a/discordbot/stocks/technical_analysis/rsi.py b/discordbot/stocks/technical_analysis/rsi.py index 56987a1fda6..018f6f7c3bb 100644 --- a/discordbot/stocks/technical_analysis/rsi.py +++ b/discordbot/stocks/technical_analysis/rsi.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,7 +21,16 @@ async def rsi_command( # Debug if cfg.DEBUG: - print(f"!stocks.ta.rsi {ticker} {length} {scalar} {drift} {start} {end}") + # pylint: disable=logging-too-many-args + logger.debug( + "!stocks.ta.rsi %s %s %s %s %s %s", + ticker, + length, + scalar, + drift, + start, + end, + ) # Check for argument if ticker == "": @@ -87,7 +96,7 @@ async def rsi_command( uploaded_image = gst_imgur.upload_image("ta_rsi.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Relative-Strength-Index " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/sma.py b/discordbot/stocks/technical_analysis/sma.py index e6627df7ad1..8ffd56e6028 100644 --- a/discordbot/stocks/technical_analysis/sma.py +++ b/discordbot/stocks/technical_analysis/sma.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import overlap_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def sma_command(ctx, ticker="", window="", offset="", start="", end=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.ta.sma {ticker} {window} {offset} {start} {end}") + logger.debug( + "!stocks.ta.sma %s %s %s %s %s", + ticker, + window, + offset, + start, + end, + ) # Check for argument if ticker == "": @@ -100,7 +107,7 @@ async def sma_command(ctx, ticker="", window="", offset="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_sma.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Simple-Moving-Average " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/stoch.py b/discordbot/stocks/technical_analysis/stoch.py index c10abd7108b..c7d52e8cf5e 100644 --- a/discordbot/stocks/technical_analysis/stoch.py +++ b/discordbot/stocks/technical_analysis/stoch.py @@ -8,7 +8,7 @@ from gamestonk_terminal.common.technical_analysis import momentum_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -21,7 +21,15 @@ async def stoch_command( # Debug if cfg.DEBUG: - print(f"!stocks.ta.stoch {ticker} {fast_k} {slow_k} {slow_d} {start} {end}") + logger.debug( + "!stocks.ta.stoch %s %s %s %s %s %s", + ticker, + fast_k, + slow_k, + slow_d, + start, + end, + ) # Check for argument if ticker == "": @@ -93,7 +101,7 @@ async def stoch_command( uploaded_image = gst_imgur.upload_image("ta_stoch.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Stochastic-Relative-Strength-Index " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/summary.py b/discordbot/stocks/technical_analysis/summary.py index 898d011325b..fc0a5598bab 100644 --- a/discordbot/stocks/technical_analysis/summary.py +++ b/discordbot/stocks/technical_analysis/summary.py @@ -3,6 +3,7 @@ import discord from gamestonk_terminal.stocks.technical_analysis import finbrain_model import discordbot.config_discordbot as cfg +from discordbot.run_discordbot import logger async def summary_command(ctx, ticker=""): @@ -12,7 +13,7 @@ async def summary_command(ctx, ticker=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.summary {ticker}") + logger.debug("!stocks.ta.summary %s", ticker) # Check for argument if ticker == "": diff --git a/discordbot/stocks/technical_analysis/ta_menu.py b/discordbot/stocks/technical_analysis/ta_menu.py index 7c1520b7efc..cd189d2c749 100644 --- a/discordbot/stocks/technical_analysis/ta_menu.py +++ b/discordbot/stocks/technical_analysis/ta_menu.py @@ -5,6 +5,9 @@ import discord import discord_components import discordbot.config_discordbot as cfg + +from discordbot.run_discordbot import gst_bot, logger + import discordbot.helpers from discordbot.stocks.technical_analysis.ema import ema_command @@ -30,7 +33,6 @@ from discordbot.stocks.technical_analysis.fib import fib_command from discordbot.stocks.technical_analysis.view import view_command from discordbot.stocks.technical_analysis.summary import summary_command from discordbot.stocks.technical_analysis.recom import recom_command -from discordbot.run_discordbot import gst_bot class TechnicalAnalysisCommands(discord.ext.commands.Cog): @@ -66,7 +68,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.ema") await ema_command(ctx, ticker, window, offset, start, end) @discord.ext.commands.command( @@ -96,7 +98,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.sma") await sma_command(ctx, ticker, window, offset, start, end) @discord.ext.commands.command( @@ -126,7 +128,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.wma") await wma_command(ctx, ticker, window, offset, start, end) @discord.ext.commands.command( @@ -156,7 +158,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.hma") await hma_command(ctx, ticker, window, offset, start, end) @discord.ext.commands.command( @@ -186,7 +188,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.zlma") await zlma_command(ctx, ticker, window, offset, start, end) @discord.ext.commands.command( @@ -216,7 +218,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.cci") await cci_command(ctx, ticker, length, scalar, start, end) @discord.ext.commands.command( @@ -249,7 +251,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.macd") await macd_command(ctx, ticker, fast, slow, signal, start, end) @discord.ext.commands.command( @@ -282,7 +284,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.rsi") await rsi_command(ctx, ticker, length, scalar, drift, start, end) @discord.ext.commands.command( @@ -316,7 +318,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.stoch") await stoch_command(ctx, ticker, fast_k, slow_d, slow_k, start, end) @discord.ext.commands.command( @@ -343,7 +345,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.fisher") await fisher_command(ctx, ticker, length, start, end) @discord.ext.commands.command( @@ -370,7 +372,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.cg") await cg_command(ctx, ticker, length, start, end) @discord.ext.commands.command( @@ -403,7 +405,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.adx") await adx_command(ctx, ticker, length, scalar, drift, start, end) @discord.ext.commands.command( @@ -433,7 +435,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.aroon") await aroon_command(ctx, ticker, length, scalar, start, end) @discord.ext.commands.command( @@ -466,7 +468,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.bbands") await bbands_command(ctx, ticker, length, std, ma_mode, start, end) @discord.ext.commands.command( @@ -497,10 +499,11 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.donchian") await donchian_command(ctx, ticker, upper_length, lower_length, start, end) # pylint: disable=too-many-arguments + @discord.ext.commands.command( name="stocks.ta.kc", usage="[ticker] [length] [scalar] [ma_mode] [offset] [start] [end]", @@ -535,7 +538,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.kc") await kc_command(ctx, ticker, length, scalar, ma_mode, offset, start, end) @discord.ext.commands.command( @@ -562,7 +565,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.ad") await ad_command(ctx, ticker, is_open, start, end) @discord.ext.commands.command( @@ -595,7 +598,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.adosc") await adosc_command(ctx, ticker, is_open, fast, slow, start, end) @discord.ext.commands.command(name="stocks.ta.obv", usage="[ticker] [start] [end]") @@ -611,7 +614,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.obv") await obv_command(ctx, ticker, start, end) @discord.ext.commands.command(name="stocks.ta.fib", usage="[ticker] [start] [end]") @@ -627,7 +630,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): end: Ending date in YYYY-MM-DD format """ - + logger.info("stocks.ta.fib") await fib_command(ctx, ticker, start, end) @discord.ext.commands.command(name="stocks.ta.view") @@ -639,7 +642,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): ticker: str ticker """ - + logger.info("stocks.ta.view") await view_command(ctx, ticker) @discord.ext.commands.command(name="stocks.ta.summary", usage="[ticker]") @@ -651,7 +654,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): ticker: str ticker """ - + logger.info("stocks.ta.summary") await summary_command(ctx, ticker) @discord.ext.commands.command(name="stocks.ta.recom", usage="[ticker]") @@ -663,7 +666,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): ticker: str ticker """ - + logger.info("stocks.ta.recom") await recom_command(ctx, ticker) # pylint: disable=too-many-statements @@ -678,9 +681,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): Sends a message to the discord user with the commands from the stocks.ta context. The user can then select a reaction to trigger a command. """ - - if cfg.DEBUG: - print(f"!stocks.ta {ticker}") + logger.info("!stocks.ta %s", ticker) cols_temp = [] cols = [] @@ -844,8 +845,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): async def on_reaction_add(reaction, user): if user == ctx.message.author and str(reaction.emoji) in emoji_list: if reaction.emoji == "0️⃣": - if cfg.DEBUG: - print("Reaction selected: 0") + logger.info("!stocks.ta. Reaction selected: 0") if current == 0: await view_command(ctx, ticker) elif current == 1: @@ -853,8 +853,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): elif current == 2: await adosc_command(ctx, ticker) elif reaction.emoji == "1️⃣": - if cfg.DEBUG: - print("Reaction selected: 1") + logger.info("!stocks.ta. Reaction selected: 1") if current == 0: await summary_command(ctx, ticker) elif current == 1: @@ -862,8 +861,7 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): elif current == 2: await obv_command(ctx, ticker) elif reaction.emoji == "2️⃣": - if cfg.DEBUG: - print("Reaction selected: 2") + logger.info("!stocks.ta. Reaction selected: 2") if current == 0: await recom_command(ctx, ticker) elif current == 1: @@ -871,50 +869,43 @@ class TechnicalAnalysisCommands(discord.ext.commands.Cog): elif current == 2: await fib_command(ctx, ticker) elif reaction.emoji == "3️⃣": - if cfg.DEBUG: - print("Reaction selected: 3") + logger.info("!stocks.ta. Reaction selected: 3") if current == 0: await ema_command(ctx, ticker) elif current == 1: await cg_command(ctx, ticker) elif reaction.emoji == "4️⃣": - if cfg.DEBUG: - print("Reaction selected: 4") + logger.info("!stocks.ta. Reaction selected: 4") if current == 0: await sma_command(ctx, ticker) elif current == 1: await adx_command(ctx, ticker) elif reaction.emoji == "5️⃣": - if cfg.DEBUG: - print("Reaction selected: 5") + logger.info("!stocks.ta. Reaction selected: 5") if current == 0: await wma_command(ctx, ticker) elif current == 1: await aroon_command(ctx, ticker) elif reaction.emoji == "6️⃣": - if cfg.DEBUG: - print("Reaction selected: 6") + logger.info("!stocks.ta. Reaction selected: 6") if current == 0: await hma_command(ctx, ticker) elif current == 1: await bbands_command(ctx, ticker) elif reaction.emoji == "7️⃣": - if cfg.DEBUG: - print("Reaction selected: 7") + logger.info("!stocks.ta. Reaction selected: 7") if current == 0: await zlma_command(ctx, ticker) elif current == 1: await donchian_command(ctx, ticker) elif reaction.emoji == "8️⃣": - if cfg.DEBUG: - print("Reaction selected: 8") + logger.info("!stocks.ta. Reaction selected: 8") if current == 0: await cci_command(ctx, ticker) elif current == 1: await kc_command(ctx, ticker) elif reaction.emoji == "9️⃣": - if cfg.DEBUG: - print("Reaction selected: 9") + logger.info("!stocks.ta. Reaction selected: 9") if current == 0: await macd_command(ctx, ticker) elif current == 1: diff --git a/discordbot/stocks/technical_analysis/view.py b/discordbot/stocks/technical_analysis/view.py index 946b63b8a52..04cf0b5715e 100644 --- a/discordbot/stocks/technical_analysis/view.py +++ b/discordbot/stocks/technical_analysis/view.py @@ -9,7 +9,7 @@ from gamestonk_terminal.stocks.technical_analysis import finviz_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger async def view_command(ctx, ticker=""): @@ -19,7 +19,7 @@ async def view_command(ctx, ticker=""): # Debug if cfg.DEBUG: - print(f"!stocks.ta.view {ticker}") + logger.debug("!stocks.ta.view %s", ticker) # Check for argument if ticker == "": @@ -38,7 +38,7 @@ async def view_command(ctx, ticker=""): uploaded_image = gst_imgur.upload_image("ta_view.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: [Finviz] Trendlines & Data " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/wma.py b/discordbot/stocks/technical_analysis/wma.py index 3bdb9bcaf47..46768db778c 100644 --- a/discordbot/stocks/technical_analysis/wma.py +++ b/discordbot/stocks/technical_analysis/wma.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import overlap_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def wma_command(ctx, ticker="", window="", offset="", start="", end=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.ta.wma {ticker} {window} {offset} {start} {end}") + logger.debug( + "!stocks.ta.wma %s %s %s %s %s", + ticker, + window, + offset, + start, + end, + ) # Check for argument if ticker == "": @@ -100,7 +107,7 @@ async def wma_command(ctx, ticker="", window="", offset="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_wma.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Weighted-Moving-Average " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author( diff --git a/discordbot/stocks/technical_analysis/zlma.py b/discordbot/stocks/technical_analysis/zlma.py index 14756a9c59a..830e45e8227 100644 --- a/discordbot/stocks/technical_analysis/zlma.py +++ b/discordbot/stocks/technical_analysis/zlma.py @@ -9,7 +9,7 @@ from gamestonk_terminal.common.technical_analysis import overlap_model from gamestonk_terminal.config_plot import PLOT_DPI import discordbot.config_discordbot as cfg -from discordbot.run_discordbot import gst_imgur +from discordbot.run_discordbot import gst_imgur, logger import discordbot.helpers @@ -19,7 +19,14 @@ async def zlma_command(ctx, ticker="", window="", offset="", start="", end=""): try: # Debug if cfg.DEBUG: - print(f"!stocks.ta.zlma {ticker} {window} {offset} {start} {end}") + logger.debug( + "!stocks.ta.zlma %s %s %s %s %s", + ticker, + window, + offset, + start, + end, + ) # Check for argument if ticker == "": @@ -100,7 +107,7 @@ async def zlma_command(ctx, ticker="", window="", offset="", start="", end=""): uploaded_image = gst_imgur.upload_image("ta_zlma.png", title="something") image_link = uploaded_image.link if cfg.DEBUG: - print(f"Image URL: {image_link}") + logger.debug("Image URL: %s", image_link) title = "Stocks: Zero-Lag-Moving-Average " + ticker embed = discord.Embed(title=title, colour=cfg.COLOR) embed.set_author(