diff --git a/gamestonk_terminal/etf/etf_controller.py b/gamestonk_terminal/etf/etf_controller.py index 33457dd9c66..f9c15d4e6b0 100644 --- a/gamestonk_terminal/etf/etf_controller.py +++ b/gamestonk_terminal/etf/etf_controller.py @@ -69,9 +69,9 @@ class ETFController: """Process Quit command - quit the program""" return True - def call_web(self, _): + def call_web(self, other_args: List[str]): """Process web command""" - open_web() + open_web(other_args) def call_search(self, other_args: List[str]): """Process search command""" diff --git a/gamestonk_terminal/etf/stockanalysis_model.py b/gamestonk_terminal/etf/stockanalysis_model.py index 9fbaead7849..bd703791831 100644 --- a/gamestonk_terminal/etf/stockanalysis_model.py +++ b/gamestonk_terminal/etf/stockanalysis_model.py @@ -29,9 +29,44 @@ def limit_number_of_holdings(num: str) -> int: return int(num) -def open_web(): - """Opens webbrowser to the website page""" - webbrowser.open("https://stockanalysis.com/etf/") +def open_web(other_args: List[str]): + + """ + Opens webbrowser to the website page + Parameters + ---------- + other_args : List[str] + Argparse arguments + + """ + parser = argparse.ArgumentParser(prog="web", add_help=False) + parser.add_argument( + "-n", "--name", type=str, dest="name", help="Symbol to look for", required=False + ) + + try: + if other_args: + if "-" not in other_args[0]: + other_args.insert(0, "-n") + + ns_parser = parse_known_args_and_warn(parser, other_args) + + if not ns_parser: + return "" + + if not ns_parser.name: + webbrowser.open("https://stockanalysis.com/etf/") + return "" + + if ns_parser.name.upper() in etf_symbols: + webbrowser.open(f"https://stockanalysis.com/etf/{ns_parser.name.lower()}") + else: + print("ETF symbol not available") + return "" + + except Exception as e: + print(e, "\n") + return "" def name_search(other_args: List[str]): @@ -100,7 +135,7 @@ def etf_overview(other_args: List[str]): if not ns_parser: return "" - if ns_parser.name not in etf_symbols: + if ns_parser.name.upper() not in etf_symbols: print("ETF symbol not available") return "" r1 = requests.get(f"https://stockanalysis.com/etf/{ns_parser.name}")