diff --git a/gamestonk_terminal/discovery/disc_controller.py b/gamestonk_terminal/discovery/disc_controller.py index a39f67e9d1f..c7a4ac40e33 100644 --- a/gamestonk_terminal/discovery/disc_controller.py +++ b/gamestonk_terminal/discovery/disc_controller.py @@ -103,8 +103,10 @@ class DiscoveryController: # Due to Finviz implementation of Spectrum, we delete the generated spectrum figure # after saving it and displaying it to the user if self.spectrum_img_to_delete: - os.remove(self.spectrum_img_to_delete + ".jpg") - self.spectrum_img_to_delete = "" + # Confirm that file exists + if os.path.isfile(self.spectrum_img_to_delete + ".jpg"): + os.remove(self.spectrum_img_to_delete + ".jpg") + self.spectrum_img_to_delete = "" return getattr( self, "call_" + known_args.cmd, lambda: "Command not recognized!" diff --git a/gamestonk_terminal/technical_analysis/finviz_view.py b/gamestonk_terminal/technical_analysis/finviz_view.py new file mode 100644 index 00000000000..0fc3f794356 --- /dev/null +++ b/gamestonk_terminal/technical_analysis/finviz_view.py @@ -0,0 +1,43 @@ +""" Finviz View """ +__docformat__ = "numpy" + +import argparse +from typing import List +from gamestonk_terminal.helper_funcs import parse_known_args_and_warn +from finvizfinance.quote import finvizfinance +from PIL import Image + + +def view(other_args: List[str], ticker: str): + """View historical price with trendlines. [Source: Finviz] + + Parameters + ---------- + other_args : List[str] + argparse other args + ticker: str + stock ticker + """ + parser = argparse.ArgumentParser( + add_help=False, + prog="view", + description=""" + View historical price with trendlines. [Source: Finviz] + """, + ) + + try: + ns_parser = parse_known_args_and_warn(parser, other_args) + if not ns_parser: + return + + stock = finvizfinance(ticker) + stock.TickerCharts() + + img = Image.open(ticker + ".jpg") + img.show() + + print("") + + except SystemExit: + print("") diff --git a/gamestonk_terminal/technical_analysis/ta_controller.py b/gamestonk_terminal/technical_analysis/ta_controller.py index f53c8ef4e37..7362b2edb26 100644 --- a/gamestonk_terminal/technical_analysis/ta_controller.py +++ b/gamestonk_terminal/technical_analysis/ta_controller.py @@ -2,6 +2,7 @@ __docformat__ = "numpy" import argparse +import os import pandas as pd from typing import List from datetime import datetime @@ -16,6 +17,7 @@ from gamestonk_terminal.technical_analysis import volatility as ta_volatility from gamestonk_terminal.technical_analysis import volume as ta_volume from gamestonk_terminal.technical_analysis import finbrain_view from gamestonk_terminal.technical_analysis import tradingview_view +from gamestonk_terminal.technical_analysis import finviz_view from prompt_toolkit.completion import NestedCompleter @@ -27,6 +29,7 @@ class TechnicalAnalysisController: "help", "q", "quit", + "view", "summary", "recom", "ema", @@ -55,6 +58,7 @@ class TechnicalAnalysisController: self.ticker = ticker self.start = start self.interval = interval + self.delete_img = False self.ta_parser = argparse.ArgumentParser(add_help=False, prog="ta") self.ta_parser.add_argument( "cmd", @@ -79,6 +83,7 @@ class TechnicalAnalysisController: print(" q quit this menu, and shows back to main menu") print(" quit quit to abandon program") print("") + print(" view view historical data and trendlines [Finviz]") print(" summary technical summary report [FinBrain API]") print( " recom recommendation based on Technical Indicators [Tradingview API]" @@ -115,6 +120,14 @@ class TechnicalAnalysisController: """ (known_args, other_args) = self.ta_parser.parse_known_args(an_input.split()) + # Due to Finviz implementation of Spectrum, we delete the generated spectrum figure + # after saving it and displaying it to the user + if self.delete_img: + # Confirm that file exists + if os.path.isfile(self.ticker + ".jpg"): + os.remove(self.ticker + ".jpg") + self.delete_img = False + return getattr( self, "call_" + known_args.cmd, lambda: "Command not recognized!" )(other_args) @@ -131,6 +144,11 @@ class TechnicalAnalysisController: """Process Quit command - quit the program""" return True + def call_view(self, other_args: List[str]): + """Process view command""" + finviz_view.view(other_args, self.ticker) + self.delete_img = True + def call_summary(self, other_args: List[str]): """Process summary command""" finbrain_view.technical_summary_report(other_args, self.ticker)