mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-12 12:22:35 +00:00
* 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 <montezdesousa@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
94 lines
2.4 KiB
Python
94 lines
2.4 KiB
Python
from openbb_terminal.rich_config import console
|
|
from openbb_terminal.session import (
|
|
local_model as Local,
|
|
session_model,
|
|
)
|
|
from openbb_terminal.session.user import User
|
|
|
|
|
|
def get_session(email: str, password: str, token: str, save: bool):
|
|
session = ""
|
|
|
|
if token:
|
|
console.print("Creating session from token.")
|
|
session = session_model.create_session_from_token(token, save)
|
|
|
|
if not session:
|
|
console.print("Creating session from email and password.")
|
|
session = session_model.create_session(email, password, save)
|
|
|
|
if not (isinstance(session, dict) and session):
|
|
raise Exception("Failed to create session.")
|
|
|
|
return session
|
|
|
|
|
|
def login(
|
|
email: str = "", password: str = "", token: str = "", keep_session: bool = False
|
|
):
|
|
"""
|
|
Login and load user info.
|
|
If there is a saved session it will be used (this can be achieved by `keep_session=True`).
|
|
If there's not a local session,
|
|
the user can use either email and password or the OpenBB Personal Access Token.
|
|
|
|
Parameters
|
|
----------
|
|
email : str
|
|
The email.
|
|
password : str
|
|
The password.
|
|
token : str
|
|
The OpenBB Personal Access Token.
|
|
keep_session : bool
|
|
Keep the session, i.e., next time the user logs in,
|
|
there is no need to enter the email and password or the token.
|
|
|
|
Examples
|
|
--------
|
|
>>> from openbb_terminal.sdk import openbb
|
|
>>> openbb.login(email="your_email", password="your_password")
|
|
"""
|
|
|
|
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 local session to login.")
|
|
|
|
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]")
|
|
|
|
|
|
def logout():
|
|
"""
|
|
Logout and clear session.
|
|
|
|
Examples
|
|
--------
|
|
>>> from openbb_terminal.sdk import openbb
|
|
>>> openbb.logout()
|
|
"""
|
|
session_model.logout(
|
|
auth_header=User.get_auth_header(),
|
|
token=User.get_token(),
|
|
guest=User.is_guest(),
|
|
)
|
|
|
|
|
|
def whoami():
|
|
"""
|
|
Display user info.
|
|
|
|
Examples
|
|
--------
|
|
>>> from openbb_terminal.sdk import openbb
|
|
>>> openbb.whoami()
|
|
"""
|
|
User.whoami()
|