mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Improve watchlist command in reddit_api
This commit is contained in:
@@ -48,6 +48,7 @@ def watchlist(l_args):
|
||||
d_watchlist_tickers = {}
|
||||
l_watchlist_links = list()
|
||||
l_watchlist_author = list()
|
||||
ls_text = list()
|
||||
|
||||
praw_api = praw.Reddit(client_id=cfg.API_REDDIT_CLIENT_ID,
|
||||
client_secret=cfg.API_REDDIT_CLIENT_SECRET,
|
||||
@@ -76,11 +77,20 @@ def watchlist(l_args):
|
||||
if not submission.removed_by_category and submission.selftext \
|
||||
and submission.link_flair_text not in ['Yolo', 'Meme'] \
|
||||
and submission.author.name not in l_watchlist_author:
|
||||
ls_text = list()
|
||||
ls_text.append(submission.selftext)
|
||||
ls_text.append(submission.title)
|
||||
|
||||
submission.comments.replace_more(limit=0)
|
||||
for comment in submission.comments.list():
|
||||
ls_text.append(comment.body)
|
||||
|
||||
l_tickers_found = list()
|
||||
for s_text in ls_text:
|
||||
for s_ticker in set(re.findall(r'([A-Z]{3,5} )', s_text)):
|
||||
l_tickers_found.append(s_ticker.strip())
|
||||
|
||||
# Make sure there is at least 1 ticker found on the post text
|
||||
l_tickers_found = set(re.findall("[A-Z]{3,5}", submission.selftext))
|
||||
if l_tickers_found:
|
||||
|
||||
# Add another author's name to the parsed watchlists
|
||||
l_watchlist_author.append(submission.author.name)
|
||||
|
||||
@@ -146,12 +156,13 @@ def watchlist(l_args):
|
||||
# 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])
|
||||
s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, "
|
||||
if int(t_ticker[1]) > 1:
|
||||
s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, "
|
||||
n_tickers += 1
|
||||
except:
|
||||
pass
|
||||
if n_tickers:
|
||||
print("The following stock tickers have been mentioned across the previous watchlists:")
|
||||
print("The following stock tickers have been mentioned more than once across the previous watchlists:")
|
||||
print(s_watchlist_tickers[:-2]+'\n')
|
||||
print("")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user