diff --git a/openbb_terminal/config_plot.py b/openbb_terminal/config_plot.py index 3fd5e3ef1f1b..3edac01f930c 100644 --- a/openbb_terminal/config_plot.py +++ b/openbb_terminal/config_plot.py @@ -3,11 +3,18 @@ import dotenv from openbb_terminal.core.config.paths import USER_ENV_FILE, REPOSITORY_ENV_FILE +from openbb_terminal.rich_config import console dotenv.load_dotenv(USER_ENV_FILE) dotenv.load_dotenv(REPOSITORY_ENV_FILE, override=True) -PLOT_DPI = int(os.getenv("OPENBB_PLOT_DPI", "100")) +try: + PLOT_DPI = int(os.getenv("OPENBB_PLOT_DPI", "100")) +except ValueError: + PLOT_DPI = 100 + console.print( + f"[red]OPENBB_PLOT_DPI is not an integer, using default value of {PLOT_DPI}[/red]" + ) # Backend to use for plotting BACKEND = os.getenv("OPENBB_BACKEND", "None") @@ -21,12 +28,36 @@ # See more: https://matplotlib.org/stable/tutorials/introductory/usage.html#the-builtin-backends # Used when USE_PLOT_AUTOSCALING is set to False -PLOT_HEIGHT = int(os.getenv("OPENBB_PLOT_HEIGHT", "500")) -PLOT_WIDTH = int(os.getenv("OPENBB_PLOT_WIDTH", "800")) +try: + PLOT_HEIGHT = int(os.getenv("OPENBB_PLOT_HEIGHT", "500")) +except ValueError: + PLOT_HEIGHT = 500 + console.print( + "[red] Invalid value for OPENBB_PLOT_HEIGHT. Please use a number.[/red]\n" + ) +try: + PLOT_WIDTH = int(os.getenv("OPENBB_PLOT_WIDTH", "800")) +except ValueError: + PLOT_WIDTH = 800 + console.print( + "[red] Invalid value for OPENBB_PLOT_WIDTH. Please use a number.[/red]\n" + ) # Used when USE_PLOT_AUTOSCALING is set to True -PLOT_HEIGHT_PERCENTAGE = float(os.getenv("OPENBB_PLOT_HEIGHT_PERCENTAGE", "50.00")) -PLOT_WIDTH_PERCENTAGE = float(os.getenv("OPENBB_PLOT_WIDTH_PERCENTAGE", "70.00")) +try: + PLOT_HEIGHT_PERCENTAGE = float(os.getenv("OPENBB_PLOT_HEIGHT_PERCENTAGE", "50.00")) +except ValueError: + PLOT_HEIGHT_PERCENTAGE = 50.00 + console.print( + "[red] Invalid value for OPENBB_PLOT_HEIGHT_PERCENTAGE. Please use a number.[/red]\n" + ) +try: + PLOT_WIDTH_PERCENTAGE = float(os.getenv("OPENBB_PLOT_WIDTH_PERCENTAGE", "70.00")) +except ValueError: + PLOT_WIDTH_PERCENTAGE = 70.00 + console.print( + "[red] Invalid value for OPENBB_PLOT_WIDTH_PERCENTAGE. Please use a number.[/red]\n" + ) # When autoscaling is True, choose which monitor to scale to # Primary monitor = 0, secondary monitor use 1 diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index 2352116b5071..e88ec9df08a6 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -1149,6 +1149,7 @@ def replace_user_timezone(user_tz: str) -> None: """ if is_timezone_valid(user_tz): dotenv.set_key(USER_ENV_FILE, "OPENBB_TIMEZONE", user_tz) + os.environ["OPENBB_TIMEZONE"] = user_tz console.print("Timezone successfully updated", "\n") else: console.print("Timezone selected is not valid", "\n")