Merge pull request #468 from jperkins12/etf-web-update

Minor improvements to ETF menu
This commit is contained in:
DidierRLopes
2021-05-27 22:09:33 +01:00
committed by GitHub
2 changed files with 41 additions and 6 deletions

View File

@@ -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"""

View File

@@ -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}")