Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes on login #4234

Merged
merged 16 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openbb_terminal/base_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions openbb_terminal/session/sdk_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down
3 changes: 3 additions & 0 deletions openbb_terminal/session/session_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
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:]

Expand All @@ -21,3 +24,7 @@
session_controller.main()
else:
session_controller.launch_terminal()


if __name__ == "__main__":
main()