Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/reddit spacc #5067

Merged
merged 15 commits into from
May 26, 2023
32 changes: 15 additions & 17 deletions openbb_terminal/common/behavioural_analysis/reddit_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions openbb_terminal/helper_funcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helper functions."""
__docformat__ = "numpy"

# pylint: disable=too-many-lines

# IMPORTS STANDARD
Expand Down Expand Up @@ -72,6 +73,7 @@
# Command location path to be shown in the figures depending on watermark flag
command_location = ""


# pylint: disable=R1702,R0912


Expand Down Expand Up @@ -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."""
Expand Down