From 46b230f1466605f2b0ecfef041de0bbb06f07496 Mon Sep 17 00:00:00 2001 From: Henrique Joaquim Date: Wed, 15 Feb 2023 14:55:22 +0000 Subject: [PATCH] Minor fixes on login (#4234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * block logout * fix default behaviour to no ask for creds * enables to use --login on Welcome to OpenBB Terminal v2.3.1 ╭─────────────────────────────────── Home ───────────────────────────────────╮ │ │ │ Information, guides and support for the OpenBB Terminal: │ │ intro introduction on the OpenBB Terminal │ │ about discover the capabilities of the OpenBB Terminal (h │ │ support pre-populate a support ticket for our team to evalu │ │ survey fill in our 2-minute survey so we better understand │ │ update attempt to update the terminal automatically (GitHu │ │ wiki search for an expression in Wikipedia (https://www. │ │ news display news articles based on term and data source │ │ │ │ Configure your own terminal: │ │ > keys set API keys and check their validity │ │ > featflags enable and disable feature flags │ │ > sources select your preferred data sources │ │ > settings tune settings (export folder, timezone, language, p │ │ │ │ Record and execute your own .openbb routine scripts: │ │ record start recording current session │ │ stop stop session recording and convert to .openbb routi │ │ exe execute .openbb routine scripts (use exe --example │ │ │ │ Main menu: │ │ > stocks access historical pricing data, options, sector and │ │ > crypto dive into onchain data, tokenomics, circulation sup │ │ > etf exchange traded funds. Historical pricing, compare │ │ > economy global macroeconomic data, e.g. futures, yield, tre │ │ > forex foreign exchanges, quotes, forward rates for curren │ │ > futures commodities, bonds, index, bitcoin and forex │ │ > alternative alternative datasets, such as COVID and open source │ │ > funds mutual funds search, overview, holdings and sector │ │ │ │ OpenBB Toolkits: │ │ > econometrics statistical and quantitative methods for relationsh │ │ > forecast timeseries forecasting with machine learning │ │ > portfolio perform portfolio optimization and look at portfoli │ │ > dashboards interactive dashboards using voila and jupyter note │ │ > reports customizable research reports through jupyter noteb │ │ │ ╰─────────────────────────────── OpenBB Terminal v2.3.1 (https://openbb.co) ─╯ You are using the latest stable version 2023 Feb 14, 06:39 (🦋) / $ [h] help menu [q] return to previous menu [e] exit terminal [cmd -h] s e 2023 Feb 14, 06:39 (🦋) / $ The OpenBB Terminal is the result of a strong community building an investment research platform for everyone, anywhere. We are always eager to welcome new contributors and you can find our open jobs here: https://www.openbb.co/company/careers#open-roles Join us : https://openbb.co/discord Follow us : https://twitter.com/openbb_finance Ask support : https://openbb.co/support Request a feature : https://openbb.co/request-a-feature Fill in our 2-minute survey so we better understand how we can improve the OpenBB Terminal at https://openbb.co/survey In the meantime access investment research from your chatting platform using the OpenBB Bot Try it today, for FREE: https://openbb.co/products/bot * reverting the condition to the original state * openbb to match python terminal.py * adding unauthorized * reverting changes * getting the value of the status --------- Co-authored-by: Diogo Sousa Co-authored-by: James Maslek --- openbb_terminal/base_helpers.py | 3 ++- openbb_terminal/session/sdk_session.py | 11 +++++------ openbb_terminal/session/session_model.py | 3 +++ pyproject.toml | 3 ++- terminal.py | 9 ++++++++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/openbb_terminal/base_helpers.py b/openbb_terminal/base_helpers.py index 66b4c542fb9..a44980d6e5c 100644 --- a/openbb_terminal/base_helpers.py +++ b/openbb_terminal/base_helpers.py @@ -98,7 +98,8 @@ def strtobool(val): def load_dotenv_and_reload_configs(): - """Loads the dotenv files in the following order: + """ + Loads the dotenv files in the following order: 1. Repository .env file 2. Package .env file 3. User .env file diff --git a/openbb_terminal/session/sdk_session.py b/openbb_terminal/session/sdk_session.py index 3edbe7d3dd6..eac33ad98ec 100644 --- a/openbb_terminal/session/sdk_session.py +++ b/openbb_terminal/session/sdk_session.py @@ -53,15 +53,14 @@ def login( session = Local.get_session() if not session: + console.print("No local session found. Creating new session.") session = get_session(email, password, token, keep_session) else: - console.print("Using saved session to login.") + console.print("Using local session to login.") - if session_model.login(session) in [ - session_model.LoginStatus.FAILED, - session_model.LoginStatus.NO_RESPONSE, - ]: - raise Exception("Login failed.") + status = session_model.login(session) + if status != session_model.LoginStatus.SUCCESS: + raise Exception(f"Login failed with status `{status.value}`.") console.print("[green]Login successful.[/green]") diff --git a/openbb_terminal/session/session_model.py b/openbb_terminal/session/session_model.py index c4482efc9d6..c001e5628a9 100644 --- a/openbb_terminal/session/session_model.py +++ b/openbb_terminal/session/session_model.py @@ -22,6 +22,7 @@ class LoginStatus(Enum): SUCCESS = "success" FAILED = "failed" NO_RESPONSE = "no_response" + UNAUTHORIZED = "unauthorized" def create_session(email: str, password: str, save: bool) -> dict: @@ -84,6 +85,8 @@ def login(session: dict) -> LoginStatus: else None ) return LoginStatus.SUCCESS + if response.status_code == 401: + return LoginStatus.UNAUTHORIZED return LoginStatus.FAILED return LoginStatus.NO_RESPONSE diff --git a/pyproject.toml b/pyproject.toml index 72ab315124f..1e8a1cf2ca0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,13 +7,14 @@ authors = ["Didier Rodrigues Lopes"] packages = [ { include = "openbb_terminal" }, ] +include = ["terminal.py"] readme = "website/content/sdk/quickstart/installation.md" homepage = "https://openbb.co" repository = "https://github.com/OpenBB-finance/OpenBBTerminal" documentation = "https://docs.openbb.co/sdk" [tool.poetry.scripts] -openbb = 'openbb_terminal.terminal_controller:parse_args_and_run' +openbb = 'terminal:main' [tool.poetry.dependencies] python = "^3.8,<3.11, !=3.9.7" diff --git a/terminal.py b/terminal.py index 048e06c345b..2c3035fff25 100644 --- a/terminal.py +++ b/terminal.py @@ -4,7 +4,10 @@ import sys from openbb_terminal.base_helpers import load_dotenv_and_reload_configs from openbb_terminal.terminal_helper import is_auth_enabled -if __name__ == "__main__": +# pylint: disable=import-outside-toplevel + + +def main(): multiprocessing.freeze_support() sent_args = sys.argv[1:] @@ -21,3 +24,7 @@ if __name__ == "__main__": session_controller.main() else: session_controller.launch_terminal() + + +if __name__ == "__main__": + main()