diff --git a/openbb_terminal/dashboards/dashboards_controller.py b/openbb_terminal/dashboards/dashboards_controller.py index 936988c5b33..167cb772787 100644 --- a/openbb_terminal/dashboards/dashboards_controller.py +++ b/openbb_terminal/dashboards/dashboards_controller.py @@ -1,4 +1,4 @@ -"""Dashboards Module""" +"""Dashboards Module.""" __docformat__ = "numpy" import argparse @@ -11,7 +11,7 @@ import sys import threading import time from pathlib import Path -from subprocess import PIPE, STDOUT +from subprocess import PIPE, STDOUT # nosec from typing import List, Optional import dotenv @@ -37,7 +37,7 @@ JUPYTER_STARTED = False class DashboardsController(BaseController): - """Dashboards Controller class""" + """Dashboards Controller class.""" CHOICES_COMMANDS = [ "stocks", @@ -54,7 +54,7 @@ class DashboardsController(BaseController): PATH = "/dashboards/" def __init__(self, queue: Optional[List[str]] = None): - """Constructor""" + """Construct controller.""" super().__init__(queue) self.jupyter_token: Optional[str] = None self.streamlit_url: Optional[str] = None @@ -72,7 +72,7 @@ class DashboardsController(BaseController): self.completer = NestedCompleter.from_nested_dict(choices) def print_help(self): - """Print help""" + """Print help.""" mt = MenuText("dashboards/") mt.add_raw("\nVoila Apps:\n") mt.add_cmd("stocks") @@ -90,57 +90,70 @@ class DashboardsController(BaseController): @log_start_end(log=logger) def call_stocks(self, other_args: List[str]): - """Process stocks command""" + """Process stocks command.""" self.create_call_voila(other_args, "stocks", "stocks") @log_start_end(log=logger) def call_correlation(self, other_args: List[str]): - """Process correlation command""" + """Process correlation command.""" self.create_call_voila(other_args, "correlation", "correlation") @log_start_end(log=logger) def call_vsurf(self, other_args: List[str]): - """Process vsurf command""" + """Process vsurf command.""" self.create_call_voila(other_args, "vsurf", "") @log_start_end(log=logger) def call_chains(self, other_args: List[str]): - """Process chains command""" + """Process chains command.""" self.create_call_voila(other_args, "chains", "") @log_start_end(log=logger) def call_shortdata(self, other_args: List[str]): - """Process shortdata command""" + """Process shortdata command.""" self.create_call_voila(other_args, "shortdata", "") @log_start_end(log=logger) def call_crypto(self, other_args: List[str]): - """Process crypto command""" + """Process crypto command.""" self.create_call_voila(other_args, "crypto", "") @log_start_end(log=logger) def call_futures(self, other_args: List[str]): - """Process futures command""" + """Process futures command.""" self.create_call_voila(other_args, "futures", "") @log_start_end(log=logger) def call_forecast(self, other_args: List[str]): - """Process forecast command""" + """Process forecast command.""" self.create_call_voila(other_args, "forecast", "") @log_start_end(log=logger) def call_forecasting(self, other_args: List[str]): - """Process forecasting command""" + """Process forecasting command.""" self.create_call_streamlit(other_args, "Forecasting") @log_start_end(log=logger) def call_indicators(self, other_args: List[str]): - """Process indicators command""" + """Process indicators command.""" self.create_call_streamlit(other_args, "Indicators") def create_call_voila( self, other_args: List[str], name: str, filename: Optional[str] = None ) -> None: + """Create a voila call command. + + A metafunction that creates a call command for a voila dashboard. + + Parameters + ---------- + other_args : List[str] + Other arguments to pass to the voila command. + name : str + Name of the dashboard. + filename : Optional[str], optional + Filename of the dashboard, by default None + """ filename = filename if filename else name parser = argparse.ArgumentParser( @@ -231,7 +244,7 @@ class DashboardsController(BaseController): ) def get_jupyter_token(self, url: str) -> None: - """Gets the url and token for current jupyter-lab session.""" + """Get the url and token for current jupyter-lab session.""" process = psutil.Popen("jupyter-lab list", shell=True, stdout=PIPE) # nosec output = process.communicate()[0] @@ -253,7 +266,7 @@ class DashboardsController(BaseController): def check_processes( self, ns_parser: argparse.Namespace, filepath: Optional[Path] = None ) -> str: - """Checks if a process is already running, and returns the url.""" + """Check if a process is already running, and returns the url.""" if not filepath: filepath = Path(__file__).absolute() @@ -277,7 +290,7 @@ class DashboardsController(BaseController): @staticmethod def get_free_port() -> int: - """Searches for a random free port number.""" + """Search for a random free port number.""" not_free = True while not_free: port = np.random.randint(7000, 7999) @@ -290,6 +303,19 @@ class DashboardsController(BaseController): def create_call_streamlit( self, other_args: List[str], name: str, filename: Optional[str] = None ) -> None: + """Create a streamlit call command. + + A metafunction that creates a launch command for a streamlit dashboard. + + Parameters + ---------- + other_args : List[str] + Other arguments to pass to the streamlit command. + name : str + Name of the dashboard. + filename : Optional[str], optional + Filename of the dashboard, by default None + """ filename = filename if filename else name parser = argparse.ArgumentParser( @@ -368,6 +394,8 @@ class DashboardsController(BaseController): def is_streamlit_activated() -> bool: + """Check if streamlit is activated.""" + def _declined(): console.print( "\n[green]You will need to activate streamlit before running this command.[/]\n" @@ -401,7 +429,7 @@ def is_streamlit_activated() -> bool: try: console.print("\n[green]Activating streamlit. This may take a few seconds.[/]") - activate = os.system("streamlit activate") + activate = os.system("streamlit activate") # nosec: B605 B607 if activate == 0: _set_key() return True diff --git a/openbb_terminal/dashboards/widget_helpers.py b/openbb_terminal/dashboards/widget_helpers.py deleted file mode 100644 index 665b0acd852..00000000000 --- a/openbb_terminal/dashboards/widget_helpers.py +++ /dev/null @@ -1,43 +0,0 @@ -"""Widgets Helper Library. - -A library of `ipywidgets` wrappers for notebook based reports and voila dashboards. -The library includes both python code and html/css/js elements that can be found in the -`./widgets` folder. -""" -import os - -from jinja2 import Template - - -def stylesheet(): - """Load a default CSS stylesheet from file.""" - with open( - os.path.join(os.path.dirname(os.path.abspath(__file__)), "widgets", "style.css") - ) as f: - style = f.read() - return style - - -def price_card(ticker: str, price: str, price_color: str = "neutral_color") -> str: - """Prepare a styled HTML element of a 128 by 128 price card. - - Parameters - ---------- - ticker : str - Instrument ticker for the price card - price : str - Instrument price as a string - price_color : str, optional - The color of the price. Accepts "up_color", "down_color" and default "neutral_color" - - Returns - ------- - str - HTML code as string - """ - with open( - os.path.join(os.path.dirname(os.path.abspath(__file__)), "widgets", "card.j2") - ) as f: - template = Template(f.read()) - card = template.render(ticker=ticker, price=price, price_color=price_color) - return card diff --git a/openbb_terminal/dashboards/widgets/card.j2 b/openbb_terminal/dashboards/widgets/card.j2 deleted file mode 100644 index 09e630ad46b..00000000000 --- a/openbb_terminal/dashboards/widgets/card.j2 +++ /dev/null @@ -1,8 +0,0 @@ -