mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 05:52:23 +00:00
rename to personal access token
This commit is contained in:
@@ -196,4 +196,4 @@ API_TOKEN_TERMINAL_KEY = os.getenv("OPENBB_API_TOKEN_TERMINAL_KEY") or "REPLACE_
|
||||
API_STOCKSERA_KEY = os.getenv("OPENBB_API_STOCKSERA_KEY") or "REPLACE_ME"
|
||||
|
||||
# https://my.openbb.co
|
||||
API_OPENBB_KEY = os.getenv("OPENBB_API_OPENBB_KEY") or "REPLACE_ME"
|
||||
OPENBB_PERSONAL_ACCESS_TOKEN = os.getenv("OPENBB_PERSONAL_ACCESS_TOKEN") or "REPLACE_ME"
|
||||
|
||||
@@ -1166,7 +1166,7 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="openbb",
|
||||
description="Set OpenBB API key. ",
|
||||
description="Set OpenBB Personal Access Token. ",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-k",
|
||||
@@ -1176,13 +1176,13 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods
|
||||
help="key",
|
||||
)
|
||||
if not other_args:
|
||||
console.print("For your API Key, visit: https://openbb.co/\n")
|
||||
console.print("For your Personal Access Token, visit: https://openbb.co/\n")
|
||||
return
|
||||
|
||||
if other_args and "-" not in other_args[0][0]:
|
||||
other_args.insert(0, "-k")
|
||||
ns_parser = self.parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
self.status_dict["openbb"] = keys_model.set_openbb_key(
|
||||
self.status_dict["openbb"] = keys_model.set_openbb_personal_access_token(
|
||||
key=ns_parser.key, persist=True, show_output=True
|
||||
)
|
||||
|
||||
@@ -2627,13 +2627,15 @@ def check_stocksera_key(show_output: bool = False):
|
||||
return str(status)
|
||||
|
||||
|
||||
def set_openbb_key(key: str, persist: bool = False, show_output: bool = False):
|
||||
"""Set OpenBB key.
|
||||
def set_openbb_personal_access_token(
|
||||
key: str, persist: bool = False, show_output: bool = False
|
||||
):
|
||||
"""Set OpenBB Personal Access Token.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
key: str
|
||||
API key
|
||||
Personal Access Token
|
||||
persist: bool, optional
|
||||
If False, api key change will be contained to where it was changed. For example, a Jupyter notebook session.
|
||||
If True, api key change will be global, i.e. it will affect terminal environment variables.
|
||||
@@ -2651,20 +2653,20 @@ def set_openbb_key(key: str, persist: bool = False, show_output: bool = False):
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.keys.openbb(key="example_key")
|
||||
"""
|
||||
set_key("OPENBB_API_OPENBB_KEY", key, persist)
|
||||
return check_openbb_key(show_output)
|
||||
set_key("OPENBB_PERSONAL_ACCESS_TOKEN", key, persist)
|
||||
return check_openbb_personal_access_token(show_output)
|
||||
|
||||
|
||||
def check_openbb_key(show_output: bool = False):
|
||||
"""Check OpenBB key
|
||||
def check_openbb_personal_access_token(show_output: bool = False):
|
||||
"""Check OpenBB Personal Access Token
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Status of key set
|
||||
"""
|
||||
if cfg.API_OPENBB_KEY == "REPLACE_ME":
|
||||
logger.info("OpenBB key not defined")
|
||||
if cfg.OPENBB_PERSONAL_ACCESS_TOKEN == "REPLACE_ME":
|
||||
logger.info("OpenBB Personal Access Token not defined")
|
||||
status = KeyStatus.NOT_DEFINED
|
||||
else:
|
||||
try:
|
||||
@@ -2686,14 +2688,17 @@ def check_openbb_key(show_output: bool = False):
|
||||
)
|
||||
token = response.json().get("token")
|
||||
|
||||
if response.status_code == 200 and token == cfg.API_OPENBB_KEY:
|
||||
logger.info("OpenBB key defined, test passed")
|
||||
if (
|
||||
response.status_code == 200
|
||||
and token == cfg.OPENBB_PERSONAL_ACCESS_TOKEN
|
||||
):
|
||||
logger.info("OpenBB Personal Access Token defined, test passed")
|
||||
status = KeyStatus.DEFINED_TEST_PASSED
|
||||
else:
|
||||
logger.warning("OpenBB key defined, test failed")
|
||||
logger.warning("OpenBB Personal Access Token. defined, test failed")
|
||||
status = KeyStatus.DEFINED_TEST_FAILED
|
||||
except requests.exceptions.RequestException:
|
||||
logger.warning("OpenBB key defined, test failed")
|
||||
logger.warning("OpenBB Personal Access Token. defined, test failed")
|
||||
status = KeyStatus.DEFINED_TEST_FAILED
|
||||
|
||||
if show_output:
|
||||
|
||||
@@ -537,7 +537,7 @@ keys.santiment,openbb_terminal.keys_model.set_santiment_key,
|
||||
keys.tokenterminal,openbb_terminal.keys_model.set_tokenterminal_key,
|
||||
keys.shroom,openbb_terminal.keys_model.set_shroom_key,
|
||||
keys.stocksera,openbb_terminal.keys_model.set_stocksera_key,
|
||||
keys.openbb,openbb_terminal.keys_model.set_openbb_key,
|
||||
keys.openbb,openbb_terminal.keys_model.set_openbb_personal_access_token,
|
||||
futures.search,openbb_terminal.futures.yfinance_model.get_search_futures,
|
||||
futures.historical,openbb_terminal.futures.yfinance_model.get_historical_futures,openbb_terminal.futures.yfinance_view.display_historical
|
||||
futures.curve,openbb_terminal.futures.yfinance_model.get_curve_futures,openbb_terminal.futures.yfinance_view.display_curve
|
||||
|
||||
|
Reference in New Issue
Block a user