diff options
author | DidierRLopes <dro.lopes@campus.fct.unl.pt> | 2023-06-08 23:45:53 -0700 |
---|---|---|
committer | DidierRLopes <dro.lopes@campus.fct.unl.pt> | 2023-06-08 23:45:53 -0700 |
commit | 12dc5980e9d520277618e508069ca03085ea5874 (patch) | |
tree | 237e1b77dc90109249a84693427a12b1bb57c812 | |
parent | 8e06a78199e8ba36310f81213d6000e526b26a61 (diff) |
improve routine argument popup
-rw-r--r-- | openbb_terminal/core/plots/backend.py | 4 | ||||
-rw-r--r-- | openbb_terminal/routine_functions.py | 43 | ||||
-rw-r--r-- | openbb_terminal/terminal_controller.py | 3 | ||||
-rw-r--r-- | params.py | 11 |
4 files changed, 43 insertions, 18 deletions
diff --git a/openbb_terminal/core/plots/backend.py b/openbb_terminal/core/plots/backend.py index 24d295b1d7f..01d01a2d30e 100644 --- a/openbb_terminal/core/plots/backend.py +++ b/openbb_terminal/core/plots/backend.py @@ -427,8 +427,8 @@ class Backend(PyWry): self.send_outgoing(outgoing) messages_dict = dict( - message="Choose your args SHILL", - interrupt="Perfect phone call", + message=title, + interrupt="", ) try: diff --git a/openbb_terminal/routine_functions.py b/openbb_terminal/routine_functions.py index 0c0e05761ca..b17900e7253 100644 --- a/openbb_terminal/routine_functions.py +++ b/openbb_terminal/routine_functions.py @@ -1,5 +1,6 @@ import re from datetime import datetime, timedelta +from pathlib import Path from typing import Dict, List, Match, Optional, Tuple, Union from dateutil.relativedelta import relativedelta @@ -161,6 +162,8 @@ def match_and_return_openbb_keyword_date(keyword: str) -> str: def parse_openbb_script( raw_lines: List[str], script_inputs: Optional[List[str]] = None, + in_production: bool = False, + file_path: str = "", ) -> Tuple[str, str]: """ Parse .openbb script @@ -171,6 +174,10 @@ def parse_openbb_script( Lines from .openbb script script_inputs: str, optional Inputs to the script that come externally + in_production: bool, optional + Whether the script is being run in production mode or not + file_path: str, optional + Provides name of the script being run Returns ------- @@ -273,11 +280,37 @@ def parse_openbb_script( else: templine = templine.replace(match[0], values) else: - return ( - f"[red]Variable {VAR_NAME} not given " - "for current routine script.[/red]", - "", - ) + # In production we want to ask for the variable + # if it wasn't given using PyWry + if in_production: + from openbb_terminal.core.plots.backend import ( + plots_backend, + ) + + plots_backend().start(True) + args = plots_backend().call_routine( + f"Routine '{file_path}' requires variable '{VAR_NAME}'", + [VAR_NAME], + Path(__file__).parent.parent / "test.html", + ) + if args and VAR_NAME in args: + templine = templine.replace( + match[0], + args[VAR_NAME], + ) + else: + return ( + f"[red]Variable {VAR_NAME} not given " + "for current routine script.[/red]", + "", + ) + + else: + return ( + f"[red]Variable {VAR_NAME} not given " + "for current routine script.[/red]", + "", + ) # Only enters here when any other index from 0 is used else: diff --git a/openbb_terminal/terminal_controller.py b/openbb_terminal/terminal_controller.py index cc8f3ba3c59..67d65b54671 100644 --- a/openbb_terminal/terminal_controller.py +++ b/openbb_terminal/terminal_controller.py @@ -169,6 +169,7 @@ class TerminalController(BaseController): ).rglob("*.openbb") } + self.ROUTINE_CHOICES = {filename: None for filename in self.ROUTINE_FILES} self.ROUTINE_CHOICES["--file"] = { filename: None for filename in self.ROUTINE_FILES } @@ -684,6 +685,8 @@ class TerminalController(BaseController): err, parsed_script = parse_openbb_script( raw_lines=raw_lines, script_inputs=script_inputs if ns_parser.routine_args else None, + in_production=True, + file_path=file_path, ) # If there err output is not an empty string then it means there was an diff --git a/params.py b/params.py deleted file mode 100644 index c3861749b4f..00000000000 --- a/params.py +++ /dev/null @@ -1,11 +0,0 @@ -from pathlib import Path - -from openbb_terminal.core.plots.backend import plots_backend - -plots_backend().start(True) -args = plots_backend().call_routine( - "test", ["this", "cucumbers", "that"], Path(__file__).parent / "test.html" -) - -for key, value in args.items(): - print(key, value) |