From d2212cd7c3ee0241a4e148be30c442cf518156f7 Mon Sep 17 00:00:00 2001 From: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:50:29 +0100 Subject: [PATCH] Warn user when there is no personal access token (#4725) * warn user if no token found - 404 * add spaces to colors and theme application * be more explicit about which color preference is failing --------- Co-authored-by: Henrique Joaquim --- openbb_terminal/core/plots/plotly_helper.py | 25 +++++++++++---------- openbb_terminal/core/session/hub_model.py | 4 +++- openbb_terminal/settings_controller.py | 4 +++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/openbb_terminal/core/plots/plotly_helper.py b/openbb_terminal/core/plots/plotly_helper.py index 35f47d68fe9..713814aa7a6 100644 --- a/openbb_terminal/core/plots/plotly_helper.py +++ b/openbb_terminal/core/plots/plotly_helper.py @@ -87,23 +87,24 @@ class TerminalStyle: self.load_style(plt_style) self.apply_console_style(console_style) - def apply_console_style(self, style: Optional[str] = "") -> None: + def apply_console_style(self, style: Optional[str] = None) -> None: """Apply the style to the console.""" - if style in self.console_styles_available: - json_path: Optional[Path] = self.console_styles_available[style] - else: - self.load_available_styles() + if style: if style in self.console_styles_available: - json_path = self.console_styles_available[style] + json_path: Optional[Path] = self.console_styles_available[style] else: - console.print("\nInvalid console style. Using default.") - json_path = self.console_styles_available.get("dark", None) + self.load_available_styles() + if style in self.console_styles_available: + json_path = self.console_styles_available[style] + else: + console.print(f"\nInvalid console style '{style}', using default.") + json_path = self.console_styles_available.get("dark", None) - if json_path: - self.console_style = self.load_json_style(json_path) - else: - console.print("Error loading default.") + if json_path: + self.console_style = self.load_json_style(json_path) + else: + console.print("Error loading default.") def apply_style(self, style: Optional[str] = "") -> None: """Apply the style to the libraries.""" diff --git a/openbb_terminal/core/session/hub_model.py b/openbb_terminal/core/session/hub_model.py index 403dfe54db9..618c5b4224b 100644 --- a/openbb_terminal/core/session/hub_model.py +++ b/openbb_terminal/core/session/hub_model.py @@ -679,7 +679,9 @@ def get_personal_access_token( try: response = requests.get(url=url, headers=headers, timeout=timeout) - if response.status_code != 200: + if response.status_code == 404: + console.print("[red]No personal access token found.[/red]") + elif response.status_code != 200: console.print("[red]Failed to get personal access token.[/red]") return response diff --git a/openbb_terminal/settings_controller.py b/openbb_terminal/settings_controller.py index 612b2c4e8e2..a5416f012d3 100644 --- a/openbb_terminal/settings_controller.py +++ b/openbb_terminal/settings_controller.py @@ -292,6 +292,7 @@ class SettingsController(BaseController): type_="settings", auth_header=get_current_user().profile.get_auth_header(), ) + console.print("") console.print("Colors updated.") @log_start_end(log=logger) @@ -327,7 +328,8 @@ class SettingsController(BaseController): type_="terminal_style", auth_header=get_current_user().profile.get_auth_header(), ) - console.print("Theme updated.") + console.print("") + console.print("Theme updated.\n") @log_start_end(log=logger) def call_source(self, other_args: List[str]):