summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLOne2three <39175022+LOne2three@users.noreply.github.com>2023-05-26 15:42:26 +0100
committerGitHub <noreply@github.com>2023-05-26 14:42:26 +0000
commit58391c1edf9e159a8d19dd463c934256c35752e5 (patch)
treebf07ae450f2bd52cd5164b513fafde410d38edb1
parentd0b815b8f7d7d608ed10193cc57d2879a593aa16 (diff)
Hotfix/reddit spacc (#5067)
* Change logic in print_rich_table and display_spacc_community * changed comment * Changed logic in print_rich_table * Got rid of whitespace * changed comments * changed formatting * changed formatting * changed formatting * Fixed linting * sort imports * added TypeError to exception block and moved print_reddit_post to after the ticker iteration loop so that tables and tickers would be loaded at the same time * Changed logic in display_space_community to print all reddit posts to a single table * Quick fix wsb command --------- Co-authored-by: James Maslek <jmaslek11@gmail.com>
-rw-r--r--openbb_terminal/common/behavioural_analysis/reddit_view.py32
-rw-r--r--openbb_terminal/helper_funcs.py10
2 files changed, 22 insertions, 20 deletions
diff --git a/openbb_terminal/common/behavioural_analysis/reddit_view.py b/openbb_terminal/common/behavioural_analysis/reddit_view.py
index 291a2a22f5b..8fc49af7506 100644
--- a/openbb_terminal/common/behavioural_analysis/reddit_view.py
+++ b/openbb_terminal/common/behavioural_analysis/reddit_view.py
@@ -7,9 +7,9 @@ import textwrap
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 faebb941b82..5d425dfee96 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 @@ MENU_RESET = 2
# 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."""