Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/4778
Browse files Browse the repository at this point in the history
  • Loading branch information
the-praxs authored Apr 18, 2023
2 parents 9f6cd38 + 229f732 commit 0141486
Show file tree
Hide file tree
Showing 43 changed files with 132 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ def display_sentiment_analysis(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)
6 changes: 5 additions & 1 deletion openbb_terminal/core/models/profile_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class ProfileModel(BaseModel):
uuid: str = ""
email: str = ""
username: str = ""
remember: bool = True

def load_user_info(self, session: dict, email: str):
def load_user_info(self, session: dict, email: str, remember: bool):
"""Load user info from login info.
Parameters
Expand All @@ -24,12 +25,15 @@ def load_user_info(self, session: dict, email: str):
The login info.
email : str
The email.
remember : bool
Remember the session.
"""
self.token_type = session.get("token_type", "")
self.token = session.get("access_token", "")
self.uuid = session.get("uuid", "")
self.email = email
self.username = self.email[: self.email.find("@")]
self.remember = remember

def get_uuid(self) -> str:
"""Get uuid.
Expand Down
20 changes: 12 additions & 8 deletions openbb_terminal/core/session/session_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def get_user_input() -> Tuple[str, str, bool]:
message="> Password: ",
is_password=True,
)
save = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() == "y"
remember = (
s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() == "y"
)

return email, password, save
return email, password, remember


def prompt(welcome=True):
Expand All @@ -69,12 +71,12 @@ def prompt(welcome=True):
display_welcome_message()

while True:
email, password, save = get_user_input()
email, password, remember = get_user_input()
if not email:
return launch_terminal()
session = create_session(email, password, save)
session = create_session(email, password, remember)
if isinstance(session, dict) and session:
return login_and_launch(session=session)
return login_and_launch(session, remember)


def launch_terminal():
Expand All @@ -85,15 +87,17 @@ def launch_terminal():
terminal_controller.parse_args_and_run()


def login_and_launch(session: dict):
def login_and_launch(session: dict, remember: bool = False):
"""Login and launch terminal.
Parameters
----------
session : dict
The session info.
remember : bool, optional
Remember the session, by default False
"""
status = login(session)
status = login(session, remember)
if status in [LoginStatus.SUCCESS, LoginStatus.NO_RESPONSE]:
launch_terminal()
elif status == LoginStatus.FAILED:
Expand All @@ -108,7 +112,7 @@ def main():
if not local_session:
prompt()
else:
login_and_launch(session=local_session)
login_and_launch(session=local_session, remember=True)


if __name__ == "__main__":
Expand Down
28 changes: 16 additions & 12 deletions openbb_terminal/core/session/session_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from openbb_terminal.core.session.utils import run_thread
from openbb_terminal.helper_funcs import system_clear
from openbb_terminal.loggers import setup_logging
from openbb_terminal.rich_config import console
from openbb_terminal.rich_config import console, optional_rich_track

# pylint: disable=consider-using-f-string

Expand Down Expand Up @@ -76,13 +76,15 @@ def create_session_from_token(token: str, save: bool) -> Dict[Any, Any]:
return session


def login(session: dict) -> LoginStatus:
def login(session: Dict, remember: bool = False) -> LoginStatus:
"""Login and load user info.
Parameters
----------
session : dict
The session info.
remember : bool, optional
Remember the session, by default False
"""
# Create a new user:
# credentials: stored in hub, but we fallback to local (.env)
Expand All @@ -101,11 +103,11 @@ def login(session: dict) -> LoginStatus:
if response.status_code == 200:
configs = json.loads(response.content)
email = configs.get("email", "")
hub_user.profile.load_user_info(session, email)
hub_user.profile.load_user_info(session, email, remember)
set_current_user(hub_user)

auth_header = hub_user.profile.get_auth_header()
run_thread(download_and_save_routines, {"auth_header": auth_header})
download_and_save_routines(auth_header)
run_thread(
update_backend_sources, {"auth_header": auth_header, "configs": configs}
)
Expand All @@ -119,21 +121,23 @@ def login(session: dict) -> LoginStatus:
return LoginStatus.NO_RESPONSE


def download_and_save_routines(auth_header: str, silent: bool = True):
def download_and_save_routines(auth_header: str):
"""Download and save routines.
Parameters
----------
auth_header : str
The authorization header, e.g. "Bearer <token>".
silent : bool
Whether to silence the console output, by default True
"""
routines = download_routines(auth_header=auth_header, silent=silent)
for name, content in routines.items():
save_routine(
file_name=f"{name}.openbb", routine=content, force=True, silent=silent
)
try:
console.print("\nDownloading routines...")
routines = download_routines(auth_header=auth_header)
for name, content in optional_rich_track(
routines.items(), desc="Saving routines"
):
save_routine(file_name=f"{name}.openbb", routine=content, force=True)
except Exception:
console.print("[red]Failed to download and save routines.[/red]")


def update_backend_sources(auth_header, configs, silent: bool = True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ def display_crypto_sentiment_analysis(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)
2 changes: 1 addition & 1 deletion openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ def display_floor_price(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)
2 changes: 1 addition & 1 deletion openbb_terminal/cryptocurrency/onchain/shroom_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def display_dapp_stats(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down
21 changes: 5 additions & 16 deletions openbb_terminal/cryptocurrency/overview/blockchaincenter_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,13 @@ def display_altcoin_index(
fig.set_title(f"Altcoin Index (Performance based on {period} days)")
fig.add_scatter(x=df.index, y=df["Value"], mode="lines", name="Altcoin Index")

fig.add_hline(
y=75,
line_color=theme.up_color,
annotation=dict(
text="Altcoin Season (75)",
x=0.5,
xanchor="center",
),
fig.add_hline_legend(
y=75, line=dict(color=theme.up_color), name="Altcoin Season (75)"
)
fig.add_hline(
fig.add_hline_legend(
y=25,
line_color=theme.down_color,
annotation=dict(
text="Bitcoin Season (25)",
x=0.5,
xanchor="center",
yshift=-30,
),
line=dict(color=theme.down_color),
name="Bitcoin Season (25)",
)

export_data(
Expand Down
2 changes: 2 additions & 0 deletions openbb_terminal/dashboards/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def main():
"server.enableCORS": False,
"server.enableXsrfProtection": False,
"browser.serverAddress": "localhost",
"theme.font": "Fira Code, monospace",
"theme.base": "dark",
}

streamlit.web.bootstrap.load_config_options(flag_options=flag_options)
Expand Down
12 changes: 6 additions & 6 deletions openbb_terminal/economy/alphavantage_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def display_real_gdp(
fig,
)
if raw:
print_rich_table(
return print_rich_table(
gdp,
headers=["Date", "GDP"],
show_index=False,
Expand Down Expand Up @@ -192,7 +192,7 @@ def display_gdp_capita(
fig,
)
if raw:
print_rich_table(
return print_rich_table(
gdp,
headers=["Date", "GDP"],
show_index=False,
Expand Down Expand Up @@ -251,7 +251,7 @@ def display_inflation(
fig,
)
if raw:
print_rich_table(
return print_rich_table(
inf,
headers=["Date", "Inflation"],
show_index=False,
Expand Down Expand Up @@ -316,7 +316,7 @@ def display_cpi(
fig,
)
if raw:
print_rich_table(
return print_rich_table(
cpi,
headers=["Date", "CPI"],
show_index=False,
Expand Down Expand Up @@ -382,7 +382,7 @@ def display_treasury_yield(
fig,
)
if raw:
print_rich_table(
return print_rich_table(
yld,
headers=["Date", "Yield"],
title="Historical Treasury Yield",
Expand Down Expand Up @@ -444,7 +444,7 @@ def display_unemployment(
)

if raw:
print_rich_table(
return print_rich_table(
un,
headers=["Date", "GDP"],
title="US Unemployment",
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/economy/econdb_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def show_macro_data(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -228,7 +228,7 @@ def show_treasuries(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/economy/fred_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def plot_cpi(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


def format_data_to_plot(data: pd.DataFrame, detail: dict) -> Tuple[pd.DataFrame, str]:
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/economy/nasdaq_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def display_big_mac_index(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)

logger.error("Unable to get big mac data")
return console.print("[red]Unable to get big mac data[/red]\n")
18 changes: 9 additions & 9 deletions openbb_terminal/economy/oecd_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def plot_gdp(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -228,7 +228,7 @@ def plot_real_gdp(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -339,7 +339,7 @@ def plot_gdp_forecast(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -448,7 +448,7 @@ def plot_cpi(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -530,7 +530,7 @@ def plot_balance(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -625,7 +625,7 @@ def plot_revenue(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -727,7 +727,7 @@ def plot_spending(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -808,7 +808,7 @@ def plot_debt(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)


@log_start_end(log=logger)
Expand Down Expand Up @@ -892,4 +892,4 @@ def plot_trust(
fig,
)

return fig.show(external=external_axes)
return fig.show(external=raw or external_axes)
Loading

0 comments on commit 0141486

Please sign in to comment.