summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-06-12 12:35:18 +0100
committerGitHub <noreply@github.com>2024-06-12 11:35:18 +0000
commit99d2256e0feb812bd343e9a6c1899b268f8424f0 (patch)
treee27802a72f4fc45a9ab8e8598a9907b6ef1bacc5
parent413cce8302241eab4877b9282e1482c94396c0af (diff)
no prints when exporting (#6497)
-rw-r--r--cli/openbb_cli/controllers/base_platform_controller.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/cli/openbb_cli/controllers/base_platform_controller.py b/cli/openbb_cli/controllers/base_platform_controller.py
index acbec34d165..658e73b8a9f 100644
--- a/cli/openbb_cli/controllers/base_platform_controller.py
+++ b/cli/openbb_cli/controllers/base_platform_controller.py
@@ -6,6 +6,7 @@ from types import MethodType
from typing import Dict, List, Optional
import pandas as pd
+from openbb import obb
from openbb_charting.core.openbb_figure import OpenBBFigure
from openbb_cli.argparse_translator.argparse_class_processor import (
ArgparseClassProcessor,
@@ -16,8 +17,6 @@ from openbb_cli.controllers.utils import export_data, print_rich_table
from openbb_cli.session import Session
from openbb_core.app.model.obbject import OBBject
-from openbb import obb
-
session = Session()
@@ -186,30 +185,33 @@ class PlatformController(BaseController):
)
# making the dataframe available
- # either for printing or exporting (or both)
+ # either for printing or exporting
df = obbject.to_dataframe()
+ export = hasattr(ns_parser, "export") and ns_parser.export
+
if hasattr(ns_parser, "chart") and ns_parser.chart:
- obbject.show()
fig = obbject.chart.fig if obbject.chart else None
+ if not export:
+ obbject.show()
else:
if isinstance(df.columns, pd.RangeIndex):
df.columns = [str(i) for i in df.columns]
- print_rich_table(df=df, show_index=True, title=title)
+ print_rich_table(
+ df=df, show_index=True, title=title, export=export
+ )
elif isinstance(obbject, dict):
df = pd.DataFrame.from_dict(obbject, orient="columns")
- print_rich_table(df=df, show_index=True, title=title)
+ print_rich_table(
+ df=df, show_index=True, title=title, export=export
+ )
elif not isinstance(obbject, OBBject):
session.console.print(obbject)
- if (
- hasattr(ns_parser, "export")
- and ns_parser.export
- and not df.empty
- ):
+ if export and not df.empty:
sheet_name = getattr(ns_parser, "sheet_name", None)
if sheet_name and isinstance(sheet_name, list):
sheet_name = sheet_name[0]
@@ -222,7 +224,7 @@ class PlatformController(BaseController):
sheet_name=sheet_name,
figure=fig,
)
- elif hasattr(ns_parser, "export") and ns_parser.export and df.empty:
+ elif export and df.empty:
session.console.print("[yellow]No data to export.[/yellow]")
except Exception as e: