diff --git a/gamestonk_terminal/fundamental_analysis/market_watch_api.py b/gamestonk_terminal/fundamental_analysis/market_watch_api.py index 2915af7c63e..795902841a8 100644 --- a/gamestonk_terminal/fundamental_analysis/market_watch_api.py +++ b/gamestonk_terminal/fundamental_analysis/market_watch_api.py @@ -2,7 +2,13 @@ import argparse import requests import pandas as pd from bs4 import BeautifulSoup -from gamestonk_terminal.helper_funcs import get_user_agent, parse_known_args_and_warn +from gamestonk_terminal.helper_funcs import ( + get_user_agent, + parse_known_args_and_warn, + patch_pandas_text_adjustment, + financials_colored_values, +) +from gamestonk_terminal import feature_flags as gtff def income(l_args, s_ticker): @@ -52,6 +58,13 @@ def income(l_args, s_ticker): df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter) + if gtff.USE_COLOR: + df_financials = df_financials.applymap(financials_colored_values) + + patch_pandas_text_adjustment() + pd.set_option("display.max_colwidth", None) + pd.set_option("display.max_rows", None) + print(df_financials.to_string(index=False)) print("") @@ -120,6 +133,13 @@ def balance(l_args, s_ticker): df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter) + if gtff.USE_COLOR: + df_financials = df_financials.applymap(financials_colored_values) + + patch_pandas_text_adjustment() + pd.set_option("display.max_colwidth", None) + pd.set_option("display.max_rows", None) + print(df_financials.to_string(index=False)) print("") @@ -181,6 +201,13 @@ def cash(l_args, s_ticker): df_financials = prepare_df_financials(url_financials, ns_parser.b_quarter) + if gtff.USE_COLOR: + df_financials = df_financials.applymap(financials_colored_values) + + patch_pandas_text_adjustment() + pd.set_option("display.max_colwidth", None) + pd.set_option("display.max_rows", None) + print(df_financials.to_string(index=False)) print("") diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index 4dfae92c5a6..f94d2d5f3d8 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -310,6 +310,18 @@ def print_pretty_prediction(df_pred: pd.DataFrame, last_price: float): print(df_pred.to_string()) +def financials_colored_values(val: str) -> str: + if sum(c.isalpha() for c in val) < 2: + if "%" in val: + if "-" in val: + val = f"{Fore.RED}{val}{Style.RESET_ALL}" + else: + val = f"{Fore.GREEN}{val}{Style.RESET_ALL}" + elif "(" in val: + val = f"{Fore.RED}{val}{Style.RESET_ALL}" + return val + + def check_ohlc(type_ohlc: str) -> str: if bool(re.match("^[ohlca]+$", type_ohlc)): return type_ohlc