From 11308e653ec46789ca3e2c835ddeb76268ff659d Mon Sep 17 00:00:00 2001 From: didier Date: Tue, 27 Apr 2021 23:39:54 +0100 Subject: [PATCH] fix empty financials from marketwatch --- .../fundamental_analysis/market_watch_model.py | 4 ++++ .../fundamental_analysis/market_watch_view.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gamestonk_terminal/fundamental_analysis/market_watch_model.py b/gamestonk_terminal/fundamental_analysis/market_watch_model.py index fc1715949da..0d55d1d761b 100644 --- a/gamestonk_terminal/fundamental_analysis/market_watch_model.py +++ b/gamestonk_terminal/fundamental_analysis/market_watch_model.py @@ -73,6 +73,10 @@ def prepare_df_financials( a_financials_header.append(financials_header.text.strip("\n").split("\n")[0]) s_header_end_trend = ("5-year trend", "5- qtr trend")[quarter] + + if s_header_end_trend not in a_financials_header: + return pd.DataFrame() + df_financials = pd.DataFrame( columns=a_financials_header[0 : a_financials_header.index(s_header_end_trend)] ) diff --git a/gamestonk_terminal/fundamental_analysis/market_watch_view.py b/gamestonk_terminal/fundamental_analysis/market_watch_view.py index 795f88e7b7c..e8e86aa3767 100644 --- a/gamestonk_terminal/fundamental_analysis/market_watch_view.py +++ b/gamestonk_terminal/fundamental_analysis/market_watch_view.py @@ -73,7 +73,10 @@ def income(other_args: List[str], ticker: str): pd.set_option("display.max_colwidth", None) pd.set_option("display.max_rows", None) - print(df_financials.to_string(index=False)) + if df_financials.empty: + print("Marketwatch does not yet provide financials for this ticker") + else: + print(df_financials.to_string(index=False)) print("") except Exception as e: @@ -155,7 +158,10 @@ def balance(other_args: List[str], ticker: str): pd.set_option("display.max_colwidth", None) pd.set_option("display.max_rows", None) - print(df_financials.to_string(index=False)) + if df_financials.empty: + print("Marketwatch does not yet provide financials for this ticker") + else: + print(df_financials.to_string(index=False)) print("") except Exception as e: @@ -233,7 +239,10 @@ def cash(other_args: List[str], ticker: str): pd.set_option("display.max_colwidth", None) pd.set_option("display.max_rows", None) - print(df_financials.to_string(index=False)) + if df_financials.empty: + print("Marketwatch does not yet provide financials for this ticker") + else: + print(df_financials.to_string(index=False)) print("") except Exception as e: