diff --git a/openbb_terminal/common/behavioural_analysis/reddit_view.py b/openbb_terminal/common/behavioural_analysis/reddit_view.py index 291a2a22f5b0..8fc49af75065 100644 --- a/openbb_terminal/common/behavioural_analysis/reddit_view.py +++ b/openbb_terminal/common/behavioural_analysis/reddit_view.py @@ -7,9 +7,9 @@ from datetime import datetime from typing import Dict, Optional, Union -import finviz import pandas as pd import praw +from finvizfinance.screener.ticker import Ticker from openbb_terminal import OpenBBFigure, rich_config from openbb_terminal.common.behavioural_analysis import reddit_model @@ -172,33 +172,31 @@ def display_spac_community(limit: int = 10, popular: bool = False): """ subs, d_watchlist_tickers = reddit_model.get_spac_community(limit, popular) if not subs.empty: - for sub in subs.iterrows(): - print_reddit_post(sub) - console.print("") - if d_watchlist_tickers: lt_watchlist_sorted = sorted( d_watchlist_tickers.items(), key=lambda item: item[1], reverse=True ) s_watchlist_tickers = "" n_tickers = 0 + tickers = Ticker() + ticker_list = tickers.screener_view() + # validate against a list of all tickers for t_ticker in lt_watchlist_sorted: - try: - # If try doesn't trigger exception, it means that this stock exists on finviz - # thus we can print it. - finviz.get_stock(t_ticker[0]) + if t_ticker[0] in ticker_list: if int(t_ticker[1]) > 1: s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, " n_tickers += 1 - except Exception: # nosec - # console.print(e, "\n") - pass # noqa - if n_tickers: console.print( - "The following stock tickers have been mentioned more than once across the previous SPACs:" + "The following stock tickers have been mentioned more than once across the previous posts on " + "r/spaccs: " ) console.print(s_watchlist_tickers[:-2]) + print_rich_table( + pd.DataFrame(subs), + show_index=False, + title="Reddit Submission", + ) @log_start_end(log=logger) @@ -215,9 +213,9 @@ def display_wsb_community(limit: int = 10, new: bool = False): """ subs = reddit_model.get_wsb_community(limit, new) if not subs.empty: - for sub in subs.iterrows(): - print_reddit_post(sub) - console.print("") + # for sub in subs.iterrows(): + # print_reddit_post(sub) + print(print_rich_table(subs)) @log_start_end(log=logger) diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index faebb941b82d..5d425dfee96a 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -1,5 +1,6 @@ """Helper functions.""" __docformat__ = "numpy" + # pylint: disable=too-many-lines # IMPORTS STANDARD @@ -72,6 +73,7 @@ # Command location path to be shown in the figures depending on watermark flag command_location = "" + # pylint: disable=R1702,R0912 @@ -299,13 +301,15 @@ def print_rich_table( ) show_index = not isinstance(df.index, pd.RangeIndex) and show_index - + # convert non-str that are not timestamp or int into str + # eg) praw.models.reddit.subreddit.Subreddit for col in df.columns: try: if not isinstance(df[col].iloc[0], pd.Timestamp): - df[col] = pd.to_numeric(df[col]) + pd.to_numeric(df[col].iloc[0]) + except (ValueError, TypeError): - pass + df[col] = df[col].astype(str) def _get_headers(_headers: Union[List[str], pd.Index]) -> List[str]: """Check if headers are valid and return them."""