mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Prefix OPENBB_ for .env vars (#4475)
* prefix OPENBB_ for .env vars * black * remove prefix only for dataclass * remove openbb_ from setters * don't send pref if sync disabled * fix last commit * add fields methods to handlers
This commit is contained in:
@@ -159,7 +159,7 @@ class AccountController(BaseController):
|
||||
console.print(f"sync is {sync}, use --on or --off to change.")
|
||||
else:
|
||||
set_preference(
|
||||
name="OPENBB_SYNC_ENABLED",
|
||||
name="SYNC_ENABLED",
|
||||
value=ns_parser.sync,
|
||||
)
|
||||
sync = get_current_user().preferences.SYNC_ENABLED
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
# pylint: disable=too-many-instance-attributes, disable=no-member
|
||||
|
||||
|
||||
@dataclass(config=dict(validate_assignment=True))
|
||||
@@ -76,3 +76,14 @@ class CredentialsModel:
|
||||
dataclass_repr += f" {key}='{value}', \n"
|
||||
|
||||
return f"{self.__class__.__name__}(\n{dataclass_repr[:-2]}\n)"
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> dict[str, Any]:
|
||||
"""Get dict of fields."""
|
||||
return cls.__dataclass_fields__ # type: ignore
|
||||
|
||||
def get_field_value(self, field: str) -> Optional[str]:
|
||||
"""Get field value."""
|
||||
if hasattr(self, field):
|
||||
return getattr(self, field)
|
||||
return None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import NonNegativeInt, PositiveFloat, PositiveInt
|
||||
from pydantic.dataclasses import dataclass
|
||||
@@ -9,7 +9,7 @@ from openbb_terminal.core.config.paths import (
|
||||
USER_DATA_SOURCES_DEFAULT_FILE,
|
||||
)
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
# pylint: disable=too-many-instance-attributes, disable=no-member
|
||||
|
||||
|
||||
@dataclass(config=dict(validate_assignment=True, frozen=True))
|
||||
@@ -108,3 +108,14 @@ class PreferencesModel:
|
||||
dataclass_repr += f" {key}='{value}', \n"
|
||||
|
||||
return f"{self.__class__.__name__}(\n{dataclass_repr[:-2]}\n)"
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> dict[str, Any]:
|
||||
"""Get dict of fields."""
|
||||
return cls.__dataclass_fields__ # type: ignore
|
||||
|
||||
def get_field_value(self, field: str) -> Optional[str]:
|
||||
"""Get field value."""
|
||||
if hasattr(self, field):
|
||||
return getattr(self, field)
|
||||
return None
|
||||
|
||||
@@ -54,10 +54,6 @@ def set_credential(
|
||||
sync_enabled = current_user.preferences.SYNC_ENABLED
|
||||
local_user = is_local()
|
||||
|
||||
# Remove "OPENBB_" prefix from env_var
|
||||
if name.startswith("OPENBB_"):
|
||||
name = name[7:]
|
||||
|
||||
# Set credential in current user
|
||||
updated_credentials = dataclasses.replace(current_user.credentials, **{name: value})
|
||||
updated_user = dataclasses.replace(current_user, credentials=updated_credentials)
|
||||
@@ -65,16 +61,10 @@ def set_credential(
|
||||
|
||||
# Set credential in local env file
|
||||
if persist and local_user:
|
||||
set_key(str(SETTINGS_ENV_FILE), name, str(value))
|
||||
set_key(str(SETTINGS_ENV_FILE), "OPENBB_" + name, str(value))
|
||||
|
||||
# Send credential to cloud
|
||||
if (
|
||||
not local_user
|
||||
and sync_enabled
|
||||
and name not in LOCAL_KEYS
|
||||
and (name.startswith("API_") or name.startswith("OPENBB_"))
|
||||
and not login
|
||||
):
|
||||
if not local_user and sync_enabled and name not in LOCAL_KEYS and not login:
|
||||
patch_user_configs(
|
||||
key=name,
|
||||
value=str(value),
|
||||
|
||||
@@ -63,7 +63,7 @@ def load_env_to_model(
|
||||
var_name = str(loc[0]) if loc else ""
|
||||
msg = err.get("msg", "")
|
||||
var = env_dict.pop(var_name, None)
|
||||
fields = model.__dataclass_fields__ # type: ignore
|
||||
fields: dict[str, Any] = model.get_fields()
|
||||
if var and var_name in fields:
|
||||
default = fields[var_name].default
|
||||
print(f" {var_name}: {msg}, using default -> {default}")
|
||||
|
||||
@@ -34,12 +34,9 @@ def set_preference(
|
||||
"""
|
||||
|
||||
current_user = get_current_user()
|
||||
sync_enabled = current_user.preferences.SYNC_ENABLED
|
||||
local_user = is_local()
|
||||
|
||||
# Remove "OPENBB_" prefix from env_var
|
||||
if name.startswith("OPENBB_"):
|
||||
name = name[7:]
|
||||
|
||||
# Set preference in current user
|
||||
updated_preferences = dataclasses.replace(current_user.preferences, **{name: value})
|
||||
updated_user = dataclasses.replace(current_user, preferences=updated_preferences)
|
||||
@@ -47,10 +44,10 @@ def set_preference(
|
||||
|
||||
# Set preference in local env file
|
||||
if local_user:
|
||||
set_key(str(SETTINGS_ENV_FILE), name, str(value))
|
||||
set_key(str(SETTINGS_ENV_FILE), "OPENBB_" + name, str(value))
|
||||
|
||||
# Send preference to cloud
|
||||
if not login and (not local_user or name == "OPENBB_SYNC_ENABLED"):
|
||||
if not login and not local_user and (sync_enabled or name == "SYNC_ENABLED"):
|
||||
patch_user_configs(
|
||||
key=name,
|
||||
value=str(value),
|
||||
|
||||
@@ -82,40 +82,40 @@ class FeatureFlagsController(BaseController):
|
||||
def call_overwrite(self, _):
|
||||
"""Process overwrite command"""
|
||||
set_preference(
|
||||
"OPENBB_FILE_OVERWITE", not get_current_user().preferences.FILE_OVERWRITE
|
||||
"FILE_OVERWITE", not get_current_user().preferences.FILE_OVERWRITE
|
||||
)
|
||||
|
||||
def call_retryload(self, _):
|
||||
"""Process retryload command"""
|
||||
set_preference(
|
||||
"OPENBB_RETRY_WITH_LOAD", not get_current_user().preferences.RETRY_WITH_LOAD
|
||||
"RETRY_WITH_LOAD", not get_current_user().preferences.RETRY_WITH_LOAD
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_tab(self, _):
|
||||
"""Process tab command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_TABULATE_DF", not get_current_user().preferences.USE_TABULATE_DF
|
||||
"USE_TABULATE_DF", not get_current_user().preferences.USE_TABULATE_DF
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_cls(self, _):
|
||||
"""Process cls command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_CLEAR_AFTER_CMD",
|
||||
"USE_CLEAR_AFTER_CMD",
|
||||
not get_current_user().preferences.USE_CLEAR_AFTER_CMD,
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_color(self, _):
|
||||
"""Process color command"""
|
||||
set_preference("OPENBB_USE_COLOR", not get_current_user().preferences.USE_COLOR)
|
||||
set_preference("USE_COLOR", not get_current_user().preferences.USE_COLOR)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_promptkit(self, _):
|
||||
"""Process promptkit command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_PROMPT_TOOLKIT",
|
||||
"USE_PROMPT_TOOLKIT",
|
||||
not get_current_user().preferences.USE_PROMPT_TOOLKIT,
|
||||
)
|
||||
|
||||
@@ -123,7 +123,7 @@ class FeatureFlagsController(BaseController):
|
||||
def call_thoughts(self, _):
|
||||
"""Process thoughts command"""
|
||||
set_preference(
|
||||
"OPENBB_ENABLE_THOUGHTS_DAY",
|
||||
"ENABLE_THOUGHTS_DAY",
|
||||
not get_current_user().preferences.ENABLE_THOUGHTS_DAY,
|
||||
)
|
||||
|
||||
@@ -131,7 +131,7 @@ class FeatureFlagsController(BaseController):
|
||||
def call_reporthtml(self, _):
|
||||
"""Process reporthtml command"""
|
||||
set_preference(
|
||||
"OPENBB_OPEN_REPORT_AS_HTML",
|
||||
"OPEN_REPORT_AS_HTML",
|
||||
not get_current_user().preferences.OPEN_REPORT_AS_HTML,
|
||||
)
|
||||
|
||||
@@ -139,7 +139,7 @@ class FeatureFlagsController(BaseController):
|
||||
def call_exithelp(self, _):
|
||||
"""Process exithelp command"""
|
||||
set_preference(
|
||||
"OPENBB_ENABLE_EXIT_AUTO_HELP",
|
||||
"ENABLE_EXIT_AUTO_HELP",
|
||||
not get_current_user().preferences.ENABLE_EXIT_AUTO_HELP,
|
||||
)
|
||||
|
||||
@@ -147,49 +147,45 @@ class FeatureFlagsController(BaseController):
|
||||
def call_rcontext(self, _):
|
||||
"""Process rcontext command"""
|
||||
set_preference(
|
||||
"OPENBB_REMEMBER_CONTEXTS",
|
||||
"REMEMBER_CONTEXTS",
|
||||
not get_current_user().preferences.REMEMBER_CONTEXTS,
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_dt(self, _):
|
||||
"""Process dt command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_DATETIME", not get_current_user().preferences.USE_DATETIME
|
||||
)
|
||||
set_preference("USE_DATETIME", not get_current_user().preferences.USE_DATETIME)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_rich(self, _):
|
||||
"""Process rich command"""
|
||||
set_preference(
|
||||
"OPENBB_ENABLE_RICH", not get_current_user().preferences.ENABLE_RICH
|
||||
)
|
||||
set_preference("ENABLE_RICH", not get_current_user().preferences.ENABLE_RICH)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_richpanel(self, _):
|
||||
"""Process richpanel command"""
|
||||
set_preference(
|
||||
"OPENBB_ENABLE_RICH_PANEL",
|
||||
"ENABLE_RICH_PANEL",
|
||||
not get_current_user().preferences.ENABLE_RICH_PANEL,
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_ion(self, _):
|
||||
"""Process ion command"""
|
||||
set_preference("OPENBB_USE_ION", not get_current_user().preferences.USE_ION)
|
||||
set_preference("USE_ION", not get_current_user().preferences.USE_ION)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_watermark(self, _):
|
||||
"""Process watermark command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_WATERMARK", not get_current_user().preferences.USE_WATERMARK
|
||||
"USE_WATERMARK", not get_current_user().preferences.USE_WATERMARK
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_cmdloc(self, _):
|
||||
"""Process cmdloc command"""
|
||||
set_preference(
|
||||
"OPENBB_USE_CMD_LOCATION_FIGURE",
|
||||
"USE_CMD_LOCATION_FIGURE",
|
||||
not get_current_user().preferences.USE_CMD_LOCATION_FIGURE,
|
||||
)
|
||||
|
||||
@@ -198,6 +194,4 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process tbhint command"""
|
||||
if get_current_user().preferences.TOOLBAR_HINT:
|
||||
console.print("Will take effect when running terminal next.")
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_HINT", not get_current_user().preferences.TOOLBAR_HINT
|
||||
)
|
||||
set_preference("TOOLBAR_HINT", not get_current_user().preferences.TOOLBAR_HINT)
|
||||
|
||||
@@ -225,23 +225,13 @@ def get_keys(show: bool = False) -> pd.DataFrame:
|
||||
COINGLASS_KEY *******
|
||||
"""
|
||||
|
||||
# TODO: Refactor api variables without prefix API_ and extend API_SOURCE_KEY format
|
||||
|
||||
var_list = [
|
||||
v
|
||||
for v in dir(get_current_user().credentials)
|
||||
if v.startswith("API_") or v.startswith("OPENBB_")
|
||||
]
|
||||
|
||||
current_user = get_current_user()
|
||||
current_keys = {}
|
||||
|
||||
for cfg_var_name in var_list:
|
||||
cfg_var_value = getattr(get_current_user().credentials, cfg_var_name)
|
||||
if cfg_var_value != "REPLACE_ME":
|
||||
if cfg_var_name.startswith("OPENBB_"):
|
||||
current_keys[cfg_var_name] = cfg_var_value
|
||||
else:
|
||||
current_keys[cfg_var_name[4:]] = cfg_var_value
|
||||
for k, _ in current_user.credentials.get_fields().items():
|
||||
field_value = current_user.credentials.get_field_value(field=k)
|
||||
if field_value != "REPLACE_ME":
|
||||
current_keys[k] = field_value
|
||||
|
||||
if current_keys:
|
||||
df = pd.DataFrame.from_dict(current_keys, orient="index")
|
||||
@@ -280,7 +270,7 @@ def set_av_key(key: str, persist: bool = False, show_output: bool = False) -> st
|
||||
>>> openbb.keys.av(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_KEY_ALPHAVANTAGE", key, persist)
|
||||
set_credential("API_KEY_ALPHAVANTAGE", key, persist)
|
||||
return check_av_key(show_output)
|
||||
|
||||
|
||||
@@ -347,7 +337,7 @@ def set_fmp_key(key: str, persist: bool = False, show_output: bool = False) -> s
|
||||
>>> openbb.keys.fmp(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_KEY_FINANCIALMODELINGPREP", key, persist)
|
||||
set_credential("API_KEY_FINANCIALMODELINGPREP", key, persist)
|
||||
return check_fmp_key(show_output)
|
||||
|
||||
|
||||
@@ -418,7 +408,7 @@ def set_quandl_key(key: str, persist: bool = False, show_output: bool = False) -
|
||||
>>> openbb.keys.quandl(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_KEY_QUANDL", key, persist)
|
||||
set_credential("API_KEY_QUANDL", key, persist)
|
||||
return check_quandl_key(show_output)
|
||||
|
||||
|
||||
@@ -484,7 +474,7 @@ def set_polygon_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.polygon(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_POLYGON_KEY", key, persist)
|
||||
set_credential("API_POLYGON_KEY", key, persist)
|
||||
return check_polygon_key(show_output)
|
||||
|
||||
|
||||
@@ -553,7 +543,7 @@ def set_fred_key(key: str, persist: bool = False, show_output: bool = False) ->
|
||||
>>> openbb.keys.fred(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_FRED_KEY", key, persist)
|
||||
set_credential("API_FRED_KEY", key, persist)
|
||||
return check_fred_key(show_output)
|
||||
|
||||
|
||||
@@ -621,7 +611,7 @@ def set_news_key(key: str, persist: bool = False, show_output: bool = False) ->
|
||||
>>> openbb.keys.news(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_NEWS_TOKEN", key, persist)
|
||||
set_credential("API_NEWS_TOKEN", key, persist)
|
||||
return check_news_key(show_output)
|
||||
|
||||
|
||||
@@ -689,7 +679,7 @@ def set_tradier_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.tradier(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_TRADIER_TOKEN", key, persist)
|
||||
set_credential("API_TRADIER_TOKEN", key, persist)
|
||||
return check_tradier_key(show_output)
|
||||
|
||||
|
||||
@@ -762,7 +752,7 @@ def set_cmc_key(key: str, persist: bool = False, show_output: bool = False) -> s
|
||||
>>> openbb.keys.cmc(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_CMC_KEY", key, persist)
|
||||
set_credential("API_CMC_KEY", key, persist)
|
||||
return check_cmc_key(show_output)
|
||||
|
||||
|
||||
@@ -826,7 +816,7 @@ def set_finnhub_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.finnhub(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_FINNHUB_KEY", key, persist)
|
||||
set_credential("API_FINNHUB_KEY", key, persist)
|
||||
return check_finnhub_key(show_output)
|
||||
|
||||
|
||||
@@ -916,11 +906,11 @@ def set_reddit_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_REDDIT_CLIENT_ID", client_id, persist)
|
||||
set_credential("OPENBB_API_REDDIT_CLIENT_SECRET", client_secret, persist)
|
||||
set_credential("OPENBB_API_REDDIT_PASSWORD", password, persist)
|
||||
set_credential("OPENBB_API_REDDIT_USERNAME", username, persist)
|
||||
set_credential("OPENBB_API_REDDIT_USER_AGENT", useragent, persist)
|
||||
set_credential("API_REDDIT_CLIENT_ID", client_id, persist)
|
||||
set_credential("API_REDDIT_CLIENT_SECRET", client_secret, persist)
|
||||
set_credential("API_REDDIT_PASSWORD", password, persist)
|
||||
set_credential("API_REDDIT_USERNAME", username, persist)
|
||||
set_credential("API_REDDIT_USER_AGENT", useragent, persist)
|
||||
|
||||
return check_reddit_key(show_output)
|
||||
|
||||
@@ -1012,7 +1002,7 @@ def set_bitquery_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.bitquery(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_BITQUERY_KEY", key, persist)
|
||||
set_credential("API_BITQUERY_KEY", key, persist)
|
||||
return check_bitquery_key(show_output)
|
||||
|
||||
|
||||
@@ -1102,7 +1092,7 @@ def set_twitter_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_TWITTER_BEARER_TOKEN", access_token, persist)
|
||||
set_credential("API_TWITTER_BEARER_TOKEN", access_token, persist)
|
||||
|
||||
return check_twitter_key(show_output)
|
||||
|
||||
@@ -1190,8 +1180,8 @@ def set_rh_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_RH_USERNAME", username, persist)
|
||||
set_credential("OPENBB_RH_PASSWORD", password, persist)
|
||||
set_credential("RH_USERNAME", username, persist)
|
||||
set_credential("RH_PASSWORD", password, persist)
|
||||
|
||||
return check_rh_key(show_output)
|
||||
|
||||
@@ -1267,9 +1257,9 @@ def set_degiro_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_DG_USERNAME", username, persist)
|
||||
set_credential("OPENBB_DG_PASSWORD", password, persist)
|
||||
set_credential("OPENBB_DG_TOTP_SECRET", secret, persist)
|
||||
set_credential("DG_USERNAME", username, persist)
|
||||
set_credential("DG_PASSWORD", password, persist)
|
||||
set_credential("DG_TOTP_SECRET", secret, persist)
|
||||
|
||||
return check_degiro_key(show_output)
|
||||
|
||||
@@ -1365,9 +1355,9 @@ def set_oanda_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_OANDA_ACCOUNT", account, persist)
|
||||
set_credential("OPENBB_OANDA_TOKEN", access_token, persist)
|
||||
set_credential("OPENBB_OANDA_ACCOUNT_TYPE", account_type, persist)
|
||||
set_credential("OANDA_ACCOUNT", account, persist)
|
||||
set_credential("OANDA_TOKEN", access_token, persist)
|
||||
set_credential("OANDA_ACCOUNT_TYPE", account_type, persist)
|
||||
|
||||
return check_oanda_key(show_output)
|
||||
|
||||
@@ -1452,8 +1442,8 @@ def set_binance_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_BINANCE_KEY", key, persist)
|
||||
set_credential("OPENBB_API_BINANCE_SECRET", secret, persist)
|
||||
set_credential("API_BINANCE_KEY", key, persist)
|
||||
set_credential("API_BINANCE_SECRET", secret, persist)
|
||||
|
||||
return check_binance_key(show_output)
|
||||
|
||||
@@ -1539,9 +1529,9 @@ def set_coinbase_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_COINBASE_KEY", key, persist)
|
||||
set_credential("OPENBB_API_COINBASE_SECRET", secret, persist)
|
||||
set_credential("OPENBB_API_COINBASE_PASS_PHRASE", passphrase, persist)
|
||||
set_credential("API_COINBASE_KEY", key, persist)
|
||||
set_credential("API_COINBASE_SECRET", secret, persist)
|
||||
set_credential("API_COINBASE_PASS_PHRASE", passphrase, persist)
|
||||
|
||||
return check_coinbase_key(show_output)
|
||||
|
||||
@@ -1616,7 +1606,7 @@ def set_walert_key(key: str, persist: bool = False, show_output: bool = False) -
|
||||
>>> openbb.keys.walert(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_WHALE_ALERT_KEY", key, persist)
|
||||
set_credential("API_WHALE_ALERT_KEY", key, persist)
|
||||
return check_walert_key(show_output)
|
||||
|
||||
|
||||
@@ -1689,7 +1679,7 @@ def set_glassnode_key(
|
||||
>>> openbb.keys.glassnode(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_GLASSNODE_KEY", key, persist)
|
||||
set_credential("API_GLASSNODE_KEY", key, persist)
|
||||
return check_glassnode_key(show_output)
|
||||
|
||||
|
||||
@@ -1764,7 +1754,7 @@ def set_coinglass_key(
|
||||
>>> openbb.keys.coinglass(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_COINGLASS_KEY", key, persist)
|
||||
set_credential("API_COINGLASS_KEY", key, persist)
|
||||
return check_coinglass_key(show_output)
|
||||
|
||||
|
||||
@@ -1835,7 +1825,7 @@ def set_cpanic_key(key: str, persist: bool = False, show_output: bool = False) -
|
||||
>>> openbb.keys.cpanic(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_CRYPTO_PANIC_KEY", key, persist)
|
||||
set_credential("API_CRYPTO_PANIC_KEY", key, persist)
|
||||
return check_cpanic_key(show_output)
|
||||
|
||||
|
||||
@@ -1905,7 +1895,7 @@ def set_ethplorer_key(
|
||||
>>> openbb.keys.ethplorer(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_ETHPLORER_KEY", key, persist)
|
||||
set_credential("API_ETHPLORER_KEY", key, persist)
|
||||
return check_ethplorer_key(show_output)
|
||||
|
||||
|
||||
@@ -1982,8 +1972,8 @@ def set_smartstake_key(
|
||||
)
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_SMARTSTAKE_KEY", key, persist)
|
||||
set_credential("OPENBB_API_SMARTSTAKE_TOKEN", access_token, persist)
|
||||
set_credential("API_SMARTSTAKE_KEY", key, persist)
|
||||
set_credential("API_SMARTSTAKE_TOKEN", access_token, persist)
|
||||
return check_smartstake_key(show_output)
|
||||
|
||||
|
||||
@@ -2068,7 +2058,7 @@ def set_github_key(key: str, persist: bool = False, show_output: bool = False) -
|
||||
>>> openbb.keys.github(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_GITHUB_KEY", key, persist)
|
||||
set_credential("API_GITHUB_KEY", key, persist)
|
||||
return check_github_key(show_output)
|
||||
|
||||
|
||||
@@ -2129,7 +2119,7 @@ def set_messari_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.messari(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_MESSARI_KEY", key, persist)
|
||||
set_credential("API_MESSARI_KEY", key, persist)
|
||||
return check_messari_key(show_output)
|
||||
|
||||
|
||||
@@ -2199,7 +2189,7 @@ def set_eodhd_key(key: str, persist: bool = False, show_output: bool = False) ->
|
||||
>>> openbb.keys.eodhd(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_EODHD_KEY", key, persist)
|
||||
set_credential("API_EODHD_KEY", key, persist)
|
||||
return check_eodhd_key(show_output)
|
||||
|
||||
|
||||
@@ -2268,7 +2258,7 @@ def set_santiment_key(
|
||||
>>> openbb.keys.santiment(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_SANTIMENT_KEY", key, persist)
|
||||
set_credential("API_SANTIMENT_KEY", key, persist)
|
||||
return check_santiment_key(show_output)
|
||||
|
||||
|
||||
@@ -2348,7 +2338,7 @@ def set_shroom_key(key: str, persist: bool = False, show_output: bool = False) -
|
||||
>>> openbb.keys.shroom(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_SHROOM_KEY", key, persist)
|
||||
set_credential("API_SHROOM_KEY", key, persist)
|
||||
return check_shroom_key(show_output)
|
||||
|
||||
|
||||
@@ -2423,7 +2413,7 @@ def set_tokenterminal_key(
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.keys.tokenterminal(key="example_key")
|
||||
"""
|
||||
set_credential("OPENBB_API_TOKEN_TERMINAL_KEY", key, persist)
|
||||
set_credential("API_TOKEN_TERMINAL_KEY", key, persist)
|
||||
return check_tokenterminal_key(show_output)
|
||||
|
||||
|
||||
@@ -2488,7 +2478,7 @@ def set_stocksera_key(key: str, persist: bool = False, show_output: bool = False
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.keys.stocksera(key="example_key")
|
||||
"""
|
||||
set_credential("OPENBB_API_STOCKSERA_KEY", key, persist)
|
||||
set_credential("API_STOCKSERA_KEY", key, persist)
|
||||
return check_stocksera_key(show_output)
|
||||
|
||||
|
||||
@@ -2553,7 +2543,7 @@ def set_openbb_personal_access_token(
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.keys.openbb(key="example_key")
|
||||
"""
|
||||
set_credential("OPENBB_OPENBB_PERSONAL_ACCESS_TOKEN", key, persist)
|
||||
set_credential("OPENBB_PERSONAL_ACCESS_TOKEN", key, persist)
|
||||
return check_openbb_personal_access_token(show_output)
|
||||
|
||||
|
||||
@@ -2635,7 +2625,7 @@ def set_intrinio_key(key: str, persist: bool = False, show_output: bool = False)
|
||||
>>> openbb.keys.intrinio(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_INTRINIO_KEY", key, persist)
|
||||
set_credential("API_INTRINIO_KEY", key, persist)
|
||||
return check_intrinio_key(show_output)
|
||||
|
||||
|
||||
@@ -2705,7 +2695,7 @@ def set_databento_key(
|
||||
>>> openbb.keys.databento(key="example_key")
|
||||
"""
|
||||
|
||||
set_credential("OPENBB_API_DATABENTO_KEY", key, persist)
|
||||
set_credential("API_DATABENTO_KEY", key, persist)
|
||||
return check_databento_key(show_output)
|
||||
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference(
|
||||
"OPENBB_USE_DATETIME", not get_current_user().preferences.USE_DATETIME
|
||||
"USE_DATETIME", not get_current_user().preferences.USE_DATETIME
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -253,7 +253,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
if os.path.exists(ns_parser.file):
|
||||
set_preference("OPENBB_PREFERRED_DATA_SOURCE_FILE", ns_parser.file)
|
||||
set_preference("PREFERRED_DATA_SOURCE_FILE", ns_parser.file)
|
||||
console.print("[green]Sources file changed successfully![/green]")
|
||||
else:
|
||||
console.print("[red]Couldn't find the sources file![/red]")
|
||||
@@ -270,7 +270,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference(
|
||||
"OPENBB_USE_PLOT_AUTOSCALING",
|
||||
"USE_PLOT_AUTOSCALING",
|
||||
not get_current_user().preferences.USE_PLOT_AUTOSCALING,
|
||||
)
|
||||
|
||||
@@ -295,7 +295,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser and ns_parser.value:
|
||||
set_preference("OPENBB_PLOT_DPI", ns_parser.value)
|
||||
set_preference("PLOT_DPI", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_height(self, other_args: List[str]):
|
||||
@@ -318,7 +318,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_PLOT_HEIGHT", ns_parser.value)
|
||||
set_preference("PLOT_HEIGHT", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_width(self, other_args: List[str]):
|
||||
@@ -341,7 +341,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_PLOT_WIDTH", ns_parser.value)
|
||||
set_preference("PLOT_WIDTH", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_pheight(self, other_args: List[str]):
|
||||
@@ -363,7 +363,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_PLOT_HEIGHT_PERCENTAGE", ns_parser.value)
|
||||
set_preference("PLOT_HEIGHT_PERCENTAGE", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_pwidth(self, other_args: List[str]):
|
||||
@@ -385,7 +385,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_PLOT_WIDTH_PERCENTAGE", ns_parser.value)
|
||||
set_preference("PLOT_WIDTH_PERCENTAGE", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_monitor(self, other_args: List[str]):
|
||||
@@ -407,7 +407,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_MONITOR", ns_parser.value)
|
||||
set_preference("MONITOR", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_backend(self, other_args: List[str]):
|
||||
@@ -429,7 +429,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_preference("OPENBB_BACKEND", ns_parser.value)
|
||||
set_preference("BACKEND", ns_parser.value)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_lang(self, other_args: List[str]):
|
||||
@@ -454,7 +454,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
if ns_parser.value:
|
||||
set_preference("OPENBB_USE_LANGUAGE", ns_parser.value)
|
||||
set_preference("USE_LANGUAGE", ns_parser.value)
|
||||
else:
|
||||
console.print(
|
||||
f"Languages available: {', '.join(self.languages_available)}"
|
||||
@@ -484,7 +484,7 @@ class SettingsController(BaseController):
|
||||
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser and ns_parser.timezone:
|
||||
set_preference("OPENBB_TIMEZONE", ns_parser.timezone)
|
||||
set_preference("TIMEZONE", ns_parser.timezone)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_flair(self, other_args: List[str]):
|
||||
@@ -512,7 +512,7 @@ class SettingsController(BaseController):
|
||||
else:
|
||||
ns_parser.emoji = " ".join(ns_parser.emoji)
|
||||
|
||||
set_preference("OPENBB_USE_FLAIR", ns_parser.emoji)
|
||||
set_preference("FLAIR", ns_parser.emoji)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_userdata(self, other_args: List[str]):
|
||||
@@ -550,7 +550,7 @@ class SettingsController(BaseController):
|
||||
console.print(
|
||||
f"User data to be saved in the default folder: '{default_path}'"
|
||||
)
|
||||
set_preference("OPENBB_USER_DATA_DIRECTORY", default_path)
|
||||
set_preference("USER_DATA_DIRECTORY", default_path)
|
||||
success_userdata = True
|
||||
else:
|
||||
# If the path selected does not start from the user root, give relative location from root
|
||||
@@ -564,7 +564,7 @@ class SettingsController(BaseController):
|
||||
console.print(
|
||||
f"User data to be saved in the selected folder: '{userdata_path}'"
|
||||
)
|
||||
set_preference("OPENBB_USER_DATA_DIRECTORY", userdata_path)
|
||||
set_preference("USER_DATA_DIRECTORY", userdata_path)
|
||||
success_userdata = True
|
||||
else:
|
||||
console.print(
|
||||
@@ -581,7 +581,7 @@ class SettingsController(BaseController):
|
||||
console.print(
|
||||
f"[green]Folder '{userdata_path}' successfully created.[/green]"
|
||||
)
|
||||
set_preference("OPENBB_USER_DATA_DIRECTORY", userdata_path)
|
||||
set_preference("USER_DATA_DIRECTORY", userdata_path)
|
||||
else:
|
||||
# Do not update userdata_folder path since we will keep the same as before
|
||||
console.print(
|
||||
@@ -608,7 +608,7 @@ class SettingsController(BaseController):
|
||||
if current_user.preferences.TOOLBAR_TWEET_NEWS:
|
||||
console.print("Will take effect when running terminal next.")
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_TWEET_NEWS",
|
||||
"TOOLBAR_TWEET_NEWS",
|
||||
not get_current_user().preferences.TOOLBAR_TWEET_NEWS,
|
||||
)
|
||||
|
||||
@@ -660,24 +660,24 @@ class SettingsController(BaseController):
|
||||
if ns_parser:
|
||||
if ns_parser.time:
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_TWEET_NEWS_SECONDS_BETWEEN_UPDATES",
|
||||
"TOOLBAR_TWEET_NEWS_SECONDS_BETWEEN_UPDATES",
|
||||
str(ns_parser.time),
|
||||
)
|
||||
|
||||
if ns_parser.number:
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_TWEET_NEWS_NUM_LAST_TWEETS_TO_READ",
|
||||
"TOOLBAR_TWEET_NEWS_NUM_LAST_TWEETS_TO_READ",
|
||||
str(ns_parser.number),
|
||||
)
|
||||
|
||||
if ns_parser.accounts:
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_TWEET_NEWS_ACCOUNTS_TO_TRACK",
|
||||
"TOOLBAR_TWEET_NEWS_ACCOUNTS_TO_TRACK",
|
||||
str(ns_parser.accounts),
|
||||
)
|
||||
|
||||
if ns_parser.keywords:
|
||||
set_preference(
|
||||
"OPENBB_TOOLBAR_TWEET_NEWS_KEYWORDS",
|
||||
"TOOLBAR_TWEET_NEWS_KEYWORDS",
|
||||
str(" ".join(ns_parser.keywords)),
|
||||
)
|
||||
|
||||
@@ -411,6 +411,6 @@ def first_time_user() -> bool:
|
||||
Whether or not the user is a first time user
|
||||
"""
|
||||
if SETTINGS_ENV_FILE.stat().st_size == 0:
|
||||
set_preference("OPENBB_PREVIOUS_USE", True)
|
||||
set_preference("PREVIOUS_USE", True)
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user