add back --url auto complete

This commit is contained in:
James Maslek
2023-08-14 09:57:41 -04:00
parent c000c6e3cc
commit 2c44cae0e9
7 changed files with 83 additions and 40 deletions

View File

@@ -414,7 +414,7 @@ class AccountController(BaseController):
response = Hub.download_routine(
auth_header=get_current_user().profile.get_auth_header(),
uuid=self.REMOTE_CHOICES[name],
base_url=Hub.BackendEnvironment.BASE_URL
base_url=Hub.BackendEnvironment.BASE_URL,
)
if response and response.status_code == 200:
data = [response.json(), "personal"]
@@ -502,7 +502,7 @@ class AccountController(BaseController):
response = Hub.delete_routine(
auth_header=get_current_user().profile.get_auth_header(),
uuid=self.REMOTE_CHOICES[name],
base_url=Hub.BackendEnvironment.BASE_URL
base_url=Hub.BackendEnvironment.BASE_URL,
)
if (
response

View File

@@ -213,7 +213,9 @@ def get_top_headlines(ticker: str) -> dict:
if ticker in supported_terms():
if auth_header:
data = request(f"{ULTIMA_BASE_URL}/getTopHeadlines/{ticker}", headers=auth_header)
data = request(
f"{ULTIMA_BASE_URL}/getTopHeadlines/{ticker}", headers=auth_header
)
else:
data = request(f"{ULTIMA_BASE_URL}/getTopHeadlines/{ticker}")
if (

View File

@@ -1,14 +1,13 @@
from argparse import ArgumentParser
from contextlib import contextmanager
from inspect import isfunction, unwrap
from os import environ
from types import MethodType
from typing import Callable, List
from unittest.mock import patch
from openbb_terminal.core.session.current_system import get_current_system
from openbb_terminal.helper_funcs import check_file_type_saved, check_positive
from openbb_terminal.rich_config import get_ordered_list_sources
from openbb_terminal.core.session.current_system import get_current_system
def __mock_parse_known_args_and_warn(

View File

@@ -75,7 +75,11 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods
"""
reading_order = get_reading_order()
hierarchy = "\n ".join(list(map(str, reversed(reading_order))))
return hierarchy if is_local() else f"{BackendEnvironment.HUB_URL + 'app/terminal/api-keys'}\n {hierarchy}"
return (
hierarchy
if is_local()
else f"{BackendEnvironment.HUB_URL + 'app/terminal/api-keys'}\n {hierarchy}"
)
def print_help(self, update_status: bool = True, reevaluate: bool = True):
"""Print help"""

View File

@@ -5,7 +5,6 @@ __docformat__ = "numpy"
# IMPORTS STANDARD
import argparse
import itertools
import difflib
import json
import logging
@@ -27,12 +26,11 @@ from rich.markdown import Markdown
import openbb_terminal.core.session.local_model as Local
from openbb_terminal import config_terminal
from openbb_terminal.account.show_prompt import get_show_prompt
from openbb_terminal.core.session.constants import SCRIPT_TAGS
from openbb_terminal.core.completer.choices import build_controller_choice_map
from openbb_terminal.core.config.paths import HIST_FILE_PATH
from openbb_terminal.core.session import hub_model as Hub
from openbb_terminal.core.session.constants import SCRIPT_TAGS
from openbb_terminal.core.session.current_user import get_current_user, is_local
from openbb_terminal.core.session.routines_handler import read_routine
from openbb_terminal.cryptocurrency import cryptocurrency_helpers
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
from openbb_terminal.decorators import log_start_end
@@ -953,30 +951,55 @@ class BaseController(metaclass=ABCMeta):
ns_parser = self.parse_simple_args(parser, other_args)
if ns_parser:
if not ns_parser.name:
console.print("[red]Set a routine title by using the '-n' flag. E.g. 'record -n Morning routine'[/red]")
console.print(
"[red]Set a routine title by using the '-n' flag. E.g. 'record -n Morning routine'[/red]"
)
return
tag1 = " ".join(ns_parser.tag1) if isinstance(ns_parser.tag1, list) else ns_parser.tag1
tag1 = (
" ".join(ns_parser.tag1)
if isinstance(ns_parser.tag1, list)
else ns_parser.tag1
)
if tag1 and tag1 not in SCRIPT_TAGS:
console.print(f"[red]The parameter 'tag1' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]")
console.print(
f"[red]The parameter 'tag1' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]"
)
return
tag2 = " ".join(ns_parser.tag2) if isinstance(ns_parser.tag2, list) else ns_parser.tag2
tag2 = (
" ".join(ns_parser.tag2)
if isinstance(ns_parser.tag2, list)
else ns_parser.tag2
)
if tag2 and tag2 not in SCRIPT_TAGS:
console.print(f"[red]The parameter 'tag2' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]")
console.print(
f"[red]The parameter 'tag2' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]"
)
return
tag3 = " ".join(ns_parser.tag3) if isinstance(ns_parser.tag3, list) else ns_parser.tag3
tag3 = (
" ".join(ns_parser.tag3)
if isinstance(ns_parser.tag3, list)
else ns_parser.tag3
)
if tag3 and tag3 not in SCRIPT_TAGS:
console.print(f"[red]The parameter 'tag3' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]")
console.print(
f"[red]The parameter 'tag3' needs to be one of the following {', '.join(SCRIPT_TAGS)}[/red]"
)
return
if is_local() and not ns_parser.local:
console.print("[red]Recording session to the OpenBB Hub is not supported in guest mode.[/red]")
console.print("\n[yellow]Sign to OpenBB Hub to register: http://openbb.co[/yellow]")
console.print("\n[yellow]Otherwise set the flag '-l' to save the file locally.[/yellow]")
console.print(
"[red]Recording session to the OpenBB Hub is not supported in guest mode.[/red]"
)
console.print(
"\n[yellow]Sign to OpenBB Hub to register: http://openbb.co[/yellow]"
)
console.print(
"\n[yellow]Otherwise set the flag '-l' to save the file locally.[/yellow]"
)
return
# Check if title has a valid format
@@ -984,7 +1007,9 @@ class BaseController(metaclass=ABCMeta):
# To this day, the reason why /^[a-zA-Z0-9\s]+$/ does not work is unknown
pattern = re.compile(r"^[a-zA-Z0-9\s]+(?:[a-zA-Z0-9\s]+)*$")
if not pattern.match(title):
console.print(f"[red]The title '{title}' has invalid format. Please use only digits, characters and whitespaces.[/red]")
console.print(
f"[red]Title '{title}' has invalid format. Please use only digits, characters and whitespaces.[/]"
)
return
global RECORD_SESSION
@@ -997,15 +1022,23 @@ class BaseController(metaclass=ABCMeta):
RECORD_SESSION = True
RECORD_SESSION_LOCAL_ONLY = ns_parser.local
SESSION_RECORDED_NAME = title
SESSION_RECORDED_DESCRIPTION = " ".join(ns_parser.description) if isinstance(ns_parser.description, list) else ns_parser.description
SESSION_RECORDED_DESCRIPTION = (
" ".join(ns_parser.description)
if isinstance(ns_parser.description, list)
else ns_parser.description
)
SESSION_RECORDED_TAGS = tag1 if tag1 else ""
SESSION_RECORDED_TAGS += ',' + tag2 if tag2 else ""
SESSION_RECORDED_TAGS += ',' + tag3 if tag3 else ""
SESSION_RECORDED_TAGS += "," + tag2 if tag2 else ""
SESSION_RECORDED_TAGS += "," + tag3 if tag3 else ""
SESSION_RECORDED_PUBLIC = ns_parser.public
console.print(f"[green]The routine '{title}' is successfully being recorded.[/green]")
console.print("\n[yellow]Remember to run 'stop' command when you are done!\n[/yellow]")
console.print(
f"[green]The routine '{title}' is successfully being recorded.[/green]"
)
console.print(
"\n[yellow]Remember to run 'stop' command when you are done!\n[/yellow]"
)
@log_start_end(log=logger)
def call_stop(self, _) -> None:
@@ -1028,11 +1061,13 @@ class BaseController(metaclass=ABCMeta):
# This works regardless of whether they are logged in or not
if RECORD_SESSION_LOCAL_ONLY:
# Whitespaces are replaced by underscores and an .openbb extension is added
title_for_local_storage = SESSION_RECORDED_NAME.replace(" ", "_") + ".openbb"
title_for_local_storage = (
SESSION_RECORDED_NAME.replace(" ", "_") + ".openbb"
)
routine_file = os.path.join(
current_user.preferences.USER_ROUTINES_DIRECTORY,
title_for_local_storage
title_for_local_storage,
)
# If file already exists, add a timestamp to the name
@@ -1043,18 +1078,21 @@ class BaseController(metaclass=ABCMeta):
)
console.print("")
while i.lower() not in ["y", "yes", "n", "no"]:
i = console.input(
"Select 'y' or 'n' to proceed: "
)
i = console.input("Select 'y' or 'n' to proceed: ")
console.print("")
if i.lower() in ["n", "no"]:
new_name = datetime.now().strftime("%Y%m%d_%H%M%S_") + title_for_local_storage
new_name = (
datetime.now().strftime("%Y%m%d_%H%M%S_")
+ title_for_local_storage
)
routine_file = os.path.join(
current_user.preferences.USER_ROUTINES_DIRECTORY,
new_name,
)
console.print(f"[yellow]The routine name has been updated to '{new_name}'[/yellow]\n")
console.print(
f"[yellow]The routine name has been updated to '{new_name}'[/yellow]\n"
)
# Writing to file
with open(routine_file, "w") as file1:

View File

@@ -4,7 +4,6 @@ __docformat__ = "numpy"
import datetime
import logging
import warnings
from os import environ
from typing import Any, Dict
import numpy as np
@@ -12,6 +11,7 @@ import pandas as pd
import yfinance as yf
from tqdm import tqdm
from openbb_terminal.core.session.current_system import get_current_system
from openbb_terminal.decorators import log_start_end
from openbb_terminal.portfolio.allocation_model import get_allocation
from openbb_terminal.portfolio.portfolio_helper import (
@@ -21,7 +21,6 @@ from openbb_terminal.portfolio.portfolio_helper import (
from openbb_terminal.rich_config import console
from openbb_terminal.stocks.fundamental_analysis.yahoo_finance_model import get_splits
from openbb_terminal.terminal_helper import suppress_stdout
from openbb_terminal.core.session.current_system import get_current_system
# pylint: disable=E1136,W0201,R0902,C0302
# pylint: disable=unsupported-assignment-operation,redefined-outer-name

View File

@@ -20,7 +20,6 @@ import certifi
import pandas as pd
import requests
from prompt_toolkit import PromptSession
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
from prompt_toolkit.formatted_text import HTML
from prompt_toolkit.styles import Style
@@ -33,11 +32,11 @@ from openbb_terminal.core.config.paths import (
REPOSITORY_DIRECTORY,
SETTINGS_ENV_FILE,
)
from openbb_terminal.core.session import constants
from openbb_terminal.core.log.generation.custom_logger import log_terminal
from openbb_terminal.core.session import session_controller
from openbb_terminal.core.session import constants, session_controller
from openbb_terminal.core.session.current_system import set_system_variable
from openbb_terminal.core.session.current_user import get_current_user, set_preference
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
from openbb_terminal.helper_funcs import (
EXPORT_ONLY_RAW_DATA_ALLOWED,
check_positive,
@@ -180,12 +179,15 @@ class TerminalController(BaseController):
}
choices["exe"] = {
"--file": {filename: {} for filename in list(self.ROUTINE_FILES.keys())},
"--file": {
filename: {} for filename in list(self.ROUTINE_FILES.keys())
},
"-f": "--file",
"--example": None,
"-e": "--example",
"--input": None,
"-i": "--input",
"--url": None,
}
choices["record"] = {
@@ -776,7 +778,6 @@ class TerminalController(BaseController):
self.queue = self.queue[1:]
# pylint: disable=global-statement
def terminal(jobs_cmds: Optional[List[str]] = None, test_mode=False):
"""Terminal Menu."""