Skip to content

Commit

Permalink
Merge branch 'develop' into feature/openbb-sdk-v4
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoaquim authored Jul 27, 2023
2 parents afe4c48 + 41d1359 commit 27e1728
Show file tree
Hide file tree
Showing 10 changed files with 1,333 additions and 26 deletions.
23 changes: 23 additions & 0 deletions openbb_terminal/core/session/hub_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
import json
from typing import Any, Dict, List, Literal, Optional

import requests
from jose import jwt

from openbb_terminal.core.session.constants import (
BASE_URL,
Expand Down Expand Up @@ -53,6 +55,20 @@ def create_session(
return None


def check_token_expiration(token: str):
"""Raises ExpiredSignatureError if the token is expired."""
header_data = jwt.get_unverified_header(token)

tok = jwt.decode(
token,
key="",
algorithms=[header_data["alg"]],
options={"verify_signature": False, "verify_exp": True},
)
expiration_time = datetime.datetime.fromtimestamp(tok["exp"])
console.print(f"Token expires at {expiration_time}")


def create_session_from_token(
token: str, base_url: str = BASE_URL, timeout: int = TIMEOUT
):
Expand All @@ -67,11 +83,18 @@ def create_session_from_token(
timeout : int
The timeout, by default TIMEOUT
"""

try:
check_token_expiration(token)
data = {
"token": token,
}
return requests.post(url=base_url + "sdk/login", json=data, timeout=timeout)
except jwt.ExpiredSignatureError:
console.print(
"\n[red]Token expired. Please regenerate on the OpenBB Hub (my.openbb.co).[/red]"
)
return None
except requests.exceptions.ConnectionError:
console.print("\n[red]Connection error.[/red]")
return None
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/reports/templates/economy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
" [widgets.h(3, \"Valuation (source: Finviz)\") + valuation.to_html()]\n",
")\n",
"htmlcode += widgets.row(\n",
" [widgets.h(3, \"Performance (source: Finviz)\") + valuation.to_html()]\n",
" [widgets.h(3, \"Performance (source: Finviz)\") + performance.to_html()]\n",
")\n",
"htmlcode += widgets.row([widgets.h(3, \"US markets (source: YahooFinance)\") + eqty_0])\n",
"htmlcode += widgets.row(\n",
Expand Down Expand Up @@ -711,7 +711,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.8"
},
"vscode": {
"interpreter": {
Expand Down
444 changes: 444 additions & 0 deletions openbb_terminal/requirements-full.txt

Large diffs are not rendered by default.

298 changes: 298 additions & 0 deletions openbb_terminal/requirements.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 27e1728

Please sign in to comment.