mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Hides warning for API not being a terminal in jupyter lab (#2301)
* Fixed issue * Added fixes
This commit is contained in:
@@ -26,7 +26,6 @@ from .due_diligence.finbrain_crypto_view import (
|
||||
try:
|
||||
from .prediction_techniques import pred_api as pred
|
||||
except Exception:
|
||||
# print("Prediction API is not available.")
|
||||
pass
|
||||
|
||||
# Models
|
||||
|
||||
@@ -27,7 +27,8 @@ def display_news(
|
||||
descend: bool = False,
|
||||
export: str = "",
|
||||
) -> None:
|
||||
"""Display recent posts from CryptoPanic news aggregator platform. [Source: https://cryptopanic.com/]
|
||||
"""Display recent posts from CryptoPanic news aggregator platform.
|
||||
[Source: https://cryptopanic.com/]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -38,8 +39,8 @@ def display_news(
|
||||
filter_: Optional[str]
|
||||
Filter by kind of news. One from list: rising|hot|bullish|bearish|important|saved|lol
|
||||
region: str
|
||||
Filter news by regions. Available regions are: en (English), de (Deutsch), nl (Dutch), es (Español),
|
||||
fr (Français), it (Italiano), pt (Português), ru (Русский)
|
||||
Filter news by regions. Available regions are: en (English), de (Deutsch), nl (Dutch),
|
||||
es (Español), fr (Français), it (Italiano), pt (Português), ru (Русский)
|
||||
descend: bool
|
||||
Sort in descending order.
|
||||
export : str
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import logging
|
||||
import os
|
||||
from typing import List, Optional
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
from openbb_terminal.config_terminal import theme
|
||||
@@ -18,6 +18,7 @@ from openbb_terminal.helper_funcs import (
|
||||
is_valid_axes_count,
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from typing import Optional
|
||||
import logging
|
||||
import os
|
||||
|
||||
@@ -9,6 +10,15 @@ from prompt_toolkit.history import FileHistory
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# pylint: disable=W0104
|
||||
def is_jupyter() -> bool:
|
||||
try:
|
||||
__IPYTHON__ # type: ignore
|
||||
return True
|
||||
except NameError:
|
||||
return False
|
||||
|
||||
|
||||
def inputhook(inputhook_context):
|
||||
while not inputhook_context.input_is_ready():
|
||||
try:
|
||||
@@ -22,12 +32,18 @@ def inputhook(inputhook_context):
|
||||
history_file = os.path.join(os.path.expanduser("~"), ".openbb_terminal.his")
|
||||
|
||||
try:
|
||||
session = PromptSession(history=FileHistory(history_file)) # type: ignore
|
||||
set_eventloop_with_inputhook(inputhook)
|
||||
if not is_jupyter():
|
||||
session: Optional[PromptSession] = PromptSession(
|
||||
history=FileHistory(history_file)
|
||||
)
|
||||
set_eventloop_with_inputhook(inputhook)
|
||||
else:
|
||||
session = None
|
||||
# pylint: disable=unused-variable
|
||||
except Exception as e: # noqa: F841
|
||||
logger.exception("%s", type(e).__name__)
|
||||
print(
|
||||
"WARNING: Prompt toolkit is turned on but did not initialize successfully. Falling back to input()..."
|
||||
"WARNING: Prompt toolkit is turned on but did not initialize successfully."
|
||||
" Falling back to input()..."
|
||||
)
|
||||
session = None # type: ignore
|
||||
|
||||
@@ -13,6 +13,7 @@ from typing import List
|
||||
from pathlib import Path
|
||||
import dotenv
|
||||
|
||||
from prompt_toolkit import PromptSession
|
||||
from prompt_toolkit.completion import NestedCompleter
|
||||
from prompt_toolkit.styles import Style
|
||||
from prompt_toolkit.formatted_text import HTML
|
||||
@@ -224,7 +225,10 @@ class TerminalController(BaseController):
|
||||
|
||||
start = time.time()
|
||||
console.print(f"\n[yellow]{task}[/yellow]\n")
|
||||
an_input = session.prompt("GUESS / $ ")
|
||||
if isinstance(session, PromptSession):
|
||||
an_input = session.prompt("GUESS / $ ")
|
||||
else:
|
||||
an_input = ""
|
||||
time_dif = time.time() - start
|
||||
|
||||
# When there are multiple paths to same solution
|
||||
|
||||
Reference in New Issue
Block a user