More pylint cleanup. Locking versions of components and upgrading praw

This commit is contained in:
Artem Veremey
2021-03-01 20:32:59 -08:00
parent 6dcbc7b47c
commit 52e812eb35
5 changed files with 109 additions and 106 deletions

View File

@@ -407,7 +407,7 @@ max-attributes=11
max-bool-expr=5
# Maximum number of branch for function / method body
max-branches=35
max-branches=25
# Maximum number of locals for function / method body
max-locals=40

View File

@@ -97,6 +97,7 @@ def info(l_args, s_ticker):
# ---------------------------------------------------- MENU ----------------------------------------------------
# pylint: disable=too-many-branches
def fa_menu(s_ticker, s_start, s_interval):
# Add list of arguments that the fundamental analysis parser accepts

View File

@@ -87,108 +87,108 @@ def watchlist(l_args):
n_flair_posts_found = 0
while True:
submission = next(submissions, None)
if submission:
# Get more information about post using PRAW api
submission = praw_api.submission(id=submission.id)
# Ensure that the post hasn't been removed by moderator in the meanwhile,
# that there is a description and it's not just an image, that the flair is
# meaningful, and that we aren't re-considering same author's watchlist
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())
if l_tickers_found:
# Add another author's name to the parsed watchlists
l_watchlist_author.append(submission.author.name)
# Lookup stock tickers within a watchlist
for key in l_tickers_found:
if key in d_watchlist_tickers:
# Increment stock ticker found
d_watchlist_tickers[key] += 1
else:
# Initialize stock ticker found
d_watchlist_tickers[key] = 1
l_watchlist_links.append(
f"https://old.reddit.com{submission.permalink}"
)
# delte below, not necessary I reckon. Probably just link?
# Refactor data
s_datetime = datetime.utcfromtimestamp(
submission.created_utc
).strftime("%d/%m/%Y %H:%M:%S")
s_link = f"https://old.reddit.com{submission.permalink}"
s_all_awards = ""
for award in submission.all_awardings:
s_all_awards += f"{award['count']} {award['name']}\n"
s_all_awards = s_all_awards[:-2]
# Create dictionary with data to construct dataframe allows to save data
d_submission[submission.id] = {
"created_utc": s_datetime,
"subreddit": submission.subreddit,
"link_flair_text": submission.link_flair_text,
"title": submission.title,
"score": submission.score,
"link": s_link,
"num_comments": submission.num_comments,
"upvote_ratio": submission.upvote_ratio,
"awards": s_all_awards,
}
# Print post data collected so far
print(f"\n{s_datetime} - {submission.title}")
print(f"{s_link}")
t_post = PrettyTable(
[
"Subreddit",
"Flair",
"Score",
"# Comments",
"Upvote %",
"Awards",
]
)
t_post.add_row(
[
submission.subreddit,
submission.link_flair_text,
submission.score,
submission.num_comments,
f"{round(100*submission.upvote_ratio)}%",
s_all_awards,
]
)
print(t_post)
print("")
# Increment count of valid posts found
n_flair_posts_found += 1
# Check if number of wanted posts found has been reached
if n_flair_posts_found > ns_parser.n_limit - 1:
break
# Check if search_submissions didn't get anymore posts
else:
if not submission:
break
# Get more information about post using PRAW api
submission = praw_api.submission(id=submission.id)
# Ensure that the post hasn't been removed by moderator in the meanwhile,
# that there is a description and it's not just an image, that the flair is
# meaningful, and that we aren't re-considering same author's watchlist
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())
if l_tickers_found:
# Add another author's name to the parsed watchlists
l_watchlist_author.append(submission.author.name)
# Lookup stock tickers within a watchlist
for key in l_tickers_found:
if key in d_watchlist_tickers:
# Increment stock ticker found
d_watchlist_tickers[key] += 1
else:
# Initialize stock ticker found
d_watchlist_tickers[key] = 1
l_watchlist_links.append(
f"https://old.reddit.com{submission.permalink}"
)
# delte below, not necessary I reckon. Probably just link?
# Refactor data
s_datetime = datetime.utcfromtimestamp(
submission.created_utc
).strftime("%d/%m/%Y %H:%M:%S")
s_link = f"https://old.reddit.com{submission.permalink}"
s_all_awards = ""
for award in submission.all_awardings:
s_all_awards += f"{award['count']} {award['name']}\n"
s_all_awards = s_all_awards[:-2]
# Create dictionary with data to construct dataframe allows to save data
d_submission[submission.id] = {
"created_utc": s_datetime,
"subreddit": submission.subreddit,
"link_flair_text": submission.link_flair_text,
"title": submission.title,
"score": submission.score,
"link": s_link,
"num_comments": submission.num_comments,
"upvote_ratio": submission.upvote_ratio,
"awards": s_all_awards,
}
# Print post data collected so far
print(f"\n{s_datetime} - {submission.title}")
print(f"{s_link}")
t_post = PrettyTable(
[
"Subreddit",
"Flair",
"Score",
"# Comments",
"Upvote %",
"Awards",
]
)
t_post.add_row(
[
submission.subreddit,
submission.link_flair_text,
submission.score,
submission.num_comments,
f"{round(100*submission.upvote_ratio)}%",
s_all_awards,
]
)
print(t_post)
print("")
# Increment count of valid posts found
n_flair_posts_found += 1
# Check if number of wanted posts found has been reached
if n_flair_posts_found > ns_parser.n_limit - 1:
break
if n_flair_posts_found:

View File

@@ -20,6 +20,7 @@ cycler==0.10.0
Cython==0.29.17
decorator==4.4.2
Deprecated==1.2.11
fbprophet==0.7.1
filelock==3.0.12
finviz @ git+https://github.com/mariostoev/finviz@be8dc934e80bf03d26ddd37b4c78a5e3d57abeef
flair==0.7
@@ -50,6 +51,8 @@ kiwisolver==1.3.1
konoha==4.6.2
korean-lunar-calendar==0.2.1
langdetect==1.0.8
levenshtein==0.12.0
LunarCalendar==0.0.9
lxml==4.6.2
Markdown==3.3.4
# matplotlib==3.1.1
@@ -68,9 +71,10 @@ pandas==1.1.5
pandas-ta==0.2.23b0
papermill==2.3.2
patsy==0.5.1
plotly==4.14.3
pmdarima==1.8.0
praw==7.1.4
prawcore==1.5.0
praw==7.2.0
prawcore==2.0.0
prettytable==2.0.0
protobuf==3.15.2
psaw==0.0.12
@@ -133,6 +137,3 @@ python_dateutil==2.8.1
scikit_learn==0.24.1
tensorflow==2.4.1
zipp==3.4.0
lunarcalendar
fbprophet
levenshtein

View File

@@ -277,6 +277,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
# -----------------------------------------------------------------------------------------------------------------------
# pylint: disable=too-many-branches
def main():
"""
Gamestonk Terminal is an awesome stock market terminal that has been developed for fun,