From 4c09877dc89cb743dcd337600fd050c7e288704e Mon Sep 17 00:00:00 2001 From: James Maslek Date: Thu, 13 Oct 2022 03:28:24 -0400 Subject: [PATCH] Add --export to load functions (#2811) Co-authored-by: martinb-bb <105685594+martinb-bb@users.noreply.github.com> --- openbb_terminal/forex/forex_controller.py | 11 +++++++++-- openbb_terminal/parent_classes.py | 23 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/openbb_terminal/forex/forex_controller.py b/openbb_terminal/forex/forex_controller.py index 5df74b862dc..5f0ddee753b 100644 --- a/openbb_terminal/forex/forex_controller.py +++ b/openbb_terminal/forex/forex_controller.py @@ -18,6 +18,7 @@ from openbb_terminal.forex.forex_helper import FOREX_SOURCES, SOURCES_INTERVALS from openbb_terminal.helper_funcs import ( valid_date, EXPORT_ONLY_RAW_DATA_ALLOWED, + export_data, ) from openbb_terminal.menu import session from openbb_terminal.parent_classes import BaseController @@ -159,8 +160,7 @@ class ForexController(BaseController): other_args.insert(0, "-t") ns_parser = self.parse_known_args_and_warn( - parser, - other_args, + parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED ) if ns_parser: @@ -193,6 +193,13 @@ class ForexController(BaseController): else: self.data.index.name = "date" + export_data( + ns_parser.export, + os.path.dirname(os.path.abspath(__file__)), + "load", + self.data.copy(), + ) + self.source = ns_parser.source console.print(f"{self.from_symbol}-{self.to_symbol} loaded.\n") diff --git a/openbb_terminal/parent_classes.py b/openbb_terminal/parent_classes.py index 89f14d879e3..94db17eb5c5 100644 --- a/openbb_terminal/parent_classes.py +++ b/openbb_terminal/parent_classes.py @@ -43,6 +43,7 @@ from openbb_terminal.helper_funcs import ( parse_and_split_input, search_wikipedia, screenshot, + export_data, ) from openbb_terminal.config_terminal import theme from openbb_terminal.rich_config import console, get_ordered_list_sources @@ -979,7 +980,9 @@ class StockBaseController(BaseController, metaclass=ABCMeta): if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-t") - ns_parser = self.parse_known_args_and_warn(parser, other_args) + ns_parser = self.parse_known_args_and_warn( + parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED + ) if ns_parser: if ns_parser.weekly and ns_parser.monthly: @@ -1059,7 +1062,13 @@ class StockBaseController(BaseController, metaclass=ABCMeta): self.stock = self.stock.rename(columns={"Adj Close": "AdjClose"}) self.stock = self.stock.dropna() self.stock.columns = [x.lower() for x in self.stock.columns] - console.print("") + console.print() + export_data( + ns_parser.export, + os.path.dirname(os.path.abspath(__file__)), + "load", + self.stock.copy(), + ) class CryptoBaseController(BaseController, metaclass=ABCMeta): @@ -1151,7 +1160,9 @@ class CryptoBaseController(BaseController, metaclass=ABCMeta): if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-c") - ns_parser = self.parse_known_args_and_warn(parser, other_args) + ns_parser = self.parse_known_args_and_warn( + parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED + ) if ns_parser: if ns_parser.source in ("YahooFinance", "CoinGecko"): @@ -1181,3 +1192,9 @@ class CryptoBaseController(BaseController, metaclass=ABCMeta): ns_parser.exchange, self.current_interval, ) + export_data( + ns_parser.export, + os.path.dirname(os.path.abspath(__file__)), + "load", + self.current_df.copy(), + )