working version of stocks_load

This commit is contained in:
hjoaquim
2023-07-27 14:35:40 +01:00
parent 255138262c
commit 64a009ec42
3 changed files with 35 additions and 20 deletions

View File

@@ -6,11 +6,11 @@ from typing import (
Callable,
Dict,
List,
Literal,
Optional,
Tuple,
Type,
Union,
Literal,
Tuple,
get_args,
get_origin,
get_type_hints,
@@ -47,7 +47,7 @@ class ArgparseTranslator:
self.parser = argparse.ArgumentParser(
description=func.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=argparse.RawTextHelpFormatter,
add_help=add_help,
)
@@ -129,6 +129,8 @@ class ArgparseTranslator:
def _generate_argparse_arguments(self, parameters) -> None:
for param in parameters.values():
# TODO : how to handle kwargs?
# it's possible to add unknown arguments when parsing as follows:
# args, unknown_args = parser.parse_known_args()
if param.name == "kwargs":
continue

View File

@@ -1211,6 +1211,16 @@ class BaseController(metaclass=ABCMeta):
if current_user.preferences.USE_CLEAR_AFTER_CMD:
system_clear()
if "--help" in other_args or "-h" in other_args:
txt_help = parser.format_help() + "\n"
if parser.prog != "about":
txt_help += (
f"For more information and examples, use 'about {parser.prog}' "
f"to access the related guide.\n"
)
console.print(f"[help]{txt_help}[/help]")
return None
try:
(ns_parser, l_unknown_args) = parser.parse_known_args(other_args)
@@ -1227,16 +1237,6 @@ class BaseController(metaclass=ABCMeta):
return None
if ns_parser.help:
txt_help = parser.format_help() + "\n"
if parser.prog != "about":
txt_help += (
f"For more information and examples, use 'about {parser.prog}' "
f"to access the related guide.\n"
)
console.print(f"[help]{txt_help}[/help]")
return None
# This protects against the hidden loads in stocks/fa
if parser.prog != "load" and config_terminal.HOLD:
config_terminal.set_last_legend(" ".join(ns_parser.hold_legend_str))

View File

@@ -10,6 +10,9 @@ from typing import List, Optional
import financedatabase as fd
from argparse_translator.argparse_translator import ArgparseTranslator
# pylint: disable=R1710,import-outside-toplevel,R0913,R1702,no-member
from openbb_sdk.openbb import obb
from openbb_terminal import config_terminal
from openbb_terminal.common import (
feedparser_view,
@@ -32,8 +35,6 @@ from openbb_terminal.rich_config import MenuText, console
from openbb_terminal.stocks import cboe_view, stocks_helper, stocks_view
from openbb_terminal.terminal_helper import suppress_stdout
# pylint: disable=R1710,import-outside-toplevel,R0913,R1702,no-member
logger = logging.getLogger(__name__)
@@ -154,14 +155,26 @@ class StocksController(StockBaseController):
def call_load(self, other_args: List[str]):
"""Process load command."""
def hello_world(name: str, age: int):
print(f"Hello {name}! You are {age} years old.")
translator = ArgparseTranslator(hello_world)
translator = ArgparseTranslator(func=obb.stocks.load, add_help=False)
parser = translator.parser
if ns_parser := self.parse_known_args_and_warn(parser, other_args):
translator.execute_func(parsed_args=ns_parser)
c_out = translator.execute_func(parsed_args=ns_parser)
if c_out.error:
console.print(f"[red]{c_out.error}[/]\n")
else:
self.ticker = ns_parser.symbol
self.stock = c_out.to_dataframe()
# TODO : temporary workarround
# core gives all columns lower case and terminal expects 1st letter upper case
# upper case first letter of all columns
self.stock.columns = [
x[0].upper() + x[1:] for x in self.stock.columns.tolist()
]
c_out.show()
@log_start_end(log=logger)
def call_search(self, other_args: List[str]):