diff --git a/openbb_terminal/keys_controller.py b/openbb_terminal/keys_controller.py index 25c12b41c17..72ea8881eac 100644 --- a/openbb_terminal/keys_controller.py +++ b/openbb_terminal/keys_controller.py @@ -8,7 +8,6 @@ import logging from typing import Dict, List from tqdm import tqdm -from requests import exceptions from openbb_terminal import feature_flags as obbff, keys_view from openbb_terminal import keys_model @@ -57,23 +56,6 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods for api in tqdm(self.API_LIST, desc="Checking keys status"): self.status_dict[api] = getattr(keys_model, "check_" + str(api) + "_key")() - def is_there_at_least_one_key_defined(self) -> bool: - """Check if there is at least 1 API key defined. - This is a good proxy to understand whether we are in presence of a first time user or not - - Returns - ------- - bool - True if at least 1 key is defined, False otherwise - """ - try: - for api in self.API_LIST: - if getattr(keys_model, "check_" + str(api) + "_key")() != "not defined": - return True - except exceptions.ConnectionError: - return True - return False - def print_help(self): """Print help""" self.check_keys_status() diff --git a/openbb_terminal/keys_model.py b/openbb_terminal/keys_model.py index e9f57f6cfa7..204f1d2d929 100644 --- a/openbb_terminal/keys_model.py +++ b/openbb_terminal/keys_model.py @@ -189,6 +189,21 @@ def get_keys_info() -> Dict[str, List[str]]: return args_dict +def first_time_user() -> bool: + """Whether a user is a first time user. A first time user is someone with an empty .env file. + If this is true, it also adds an env variable to make sure this does not run again. + + Returns + ---------- + bool + Whether or not the user is a first time user + """ + if USER_ENV_FILE.stat().st_size == 0: + set_key("OPENBB_PREVIOUS_USE", "True", True) + return True + return False + + def set_key(env_var_name: str, env_var_value: str, persist: bool = False) -> None: """Set API key. Parameters diff --git a/openbb_terminal/terminal_controller.py b/openbb_terminal/terminal_controller.py index 05079665630..3d867a21b97 100644 --- a/openbb_terminal/terminal_controller.py +++ b/openbb_terminal/terminal_controller.py @@ -19,7 +19,6 @@ from prompt_toolkit.styles import Style from prompt_toolkit.formatted_text import HTML import pandas as pd from openbb_terminal import feature_flags as obbff -from openbb_terminal import keys_controller from openbb_terminal.terminal_helper import is_packaged_application from openbb_terminal.core.config.paths import ( @@ -53,6 +52,7 @@ from openbb_terminal.terminal_helper import ( welcome_message, ) from openbb_terminal.helper_funcs import parse_and_split_input +from openbb_terminal.keys_model import first_time_user from openbb_terminal.common import feedparser_view from openbb_terminal.reports.reports_model import ipykernel_launcher @@ -819,7 +819,7 @@ def terminal(jobs_cmds: List[str] = None, test_mode=False): if not jobs_cmds: welcome_message() - if not keys_controller.KeysController().is_there_at_least_one_key_defined(): + if first_time_user(): t_controller.call_intro(None) t_controller.print_help()