More pylint cleanup

This commit is contained in:
Artem Veremey
2021-02-28 20:22:42 -08:00
parent 55825c2e64
commit 702207195f
7 changed files with 76 additions and 63 deletions

View File

@@ -91,7 +91,7 @@ score=yes
[REFACTORING]
# Maximum number of nested blocks for function / method body
max-nested-blocks=5
max-nested-blocks=9
[LOGGING]
@@ -407,10 +407,10 @@ max-attributes=11
max-bool-expr=5
# Maximum number of branch for function / method body
max-branches=20
max-branches=35
# Maximum number of locals for function / method body
max-locals=15
max-locals=40
# Maximum number of parents for a class (see R0901).
max-parents=7
@@ -419,10 +419,10 @@ max-parents=7
max-public-methods=20
# Maximum number of return / yield for function / method body
max-returns=6
max-returns=9
# Maximum number of statements in function / method body
max-statements=50
max-statements=120
# Minimum number of public methods for a class (see R0903).
min-public-methods=1

View File

@@ -1,17 +1,16 @@
import pandas as pd
from pytrends.request import TrendReq
from datetime import datetime
import matplotlib.pyplot as plt
from gamestonk_terminal.helper_funcs import *
import argparse
from pytrends.request import TrendReq
import matplotlib.pyplot as plt
from gamestonk_terminal.helper_funcs import check_positive, valid_date
# -------------------------------------------------------------------------------------------------------------------
def mentions(l_args, s_ticker, s_start):
parser = argparse.ArgumentParser(
prog="mentions",
description="""Plot weekly bars of stock's interest over time. other users watchlist.
[Source: Google]""",
description="""
Plot weekly bars of stock's interest over time. other users watchlist. [Source: Google]
""",
)
parser.add_argument(
@@ -59,7 +58,8 @@ def mentions(l_args, s_ticker, s_start):
plt.show()
print("")
except:
except Exception as e:
print(e)
print("")
@@ -103,7 +103,8 @@ def regions(l_args, s_ticker):
plt.show()
print("")
except:
except Exception as e:
print(e)
print("")
@@ -142,7 +143,8 @@ def queries(l_args, s_ticker):
print(df_related_queries.to_string(index=False))
print("")
except:
except Exception as e:
print(e)
print("")
@@ -180,6 +182,6 @@ def rise(l_args, s_ticker):
print(df_related_queries.to_string(index=False))
print("")
except:
except Exception as e:
print(e)
print("")

View File

@@ -1,16 +1,14 @@
import argparse
import re
from datetime import datetime, timedelta
import warnings
from prettytable import PrettyTable
import pandas as pd
from psaw import PushshiftAPI
import praw
from pytz import timezone
from holidays import US as holidaysUS
import finviz
from gamestonk_terminal.helper_funcs import check_positive
from gamestonk_terminal import config_terminal as cfg
import warnings
# -------------------------------------------------------------------------------------------------------------------
def get_last_time_market_was_open(dt):
@@ -207,8 +205,9 @@ def watchlist(l_args):
if int(t_ticker[1]) > 1:
s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, "
n_tickers += 1
except:
pass
except Exception as e:
print(e)
# pass
if n_tickers:
print(
"The following stock tickers have been mentioned more than once across the previous watchlists:"
@@ -282,9 +281,9 @@ def popular_tickers(l_args):
"wallstreetbets",
]
d_submission = {}
# d_submission = {}
d_watchlist_tickers = {}
l_watchlist_links = list()
# l_watchlist_links = list()
l_watchlist_author = list()
praw_api = praw.Reddit(
@@ -374,8 +373,9 @@ def popular_tickers(l_args):
finviz.get_stock(t_ticker[0])
print(f"{t_ticker[1]} {t_ticker[0]}")
n_top_stocks += 1
except:
pass
except Exception as e:
print(e)
# pass
else:
print("No tickers found")
print("")
@@ -429,7 +429,7 @@ def spac_community(l_args):
l_watchlist_links = list()
l_watchlist_author = list()
psaw_api = PushshiftAPI()
# psaw_api = PushshiftAPI()
if ns_parser.b_popular:
submissions = praw_api.subreddit("SPACs").hot(limit=ns_parser.n_limit)
@@ -549,8 +549,9 @@ def spac_community(l_args):
if int(t_ticker[1]) > 1:
s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, "
n_tickers += 1
except:
pass
except Exception as e:
print(e)
# pass
if n_tickers:
print(
"The following stock tickers have been mentioned more than once across the previous SPACs:"
@@ -750,8 +751,9 @@ def spac(l_args):
if int(t_ticker[1]) > 1:
s_watchlist_tickers += f"{t_ticker[1]} {t_ticker[0]}, "
n_tickers += 1
except:
pass
except Exception as e:
print(e)
# pass
if n_tickers:
print(
"The following stock tickers have been mentioned more than once across the previous SPACs:"
@@ -806,7 +808,7 @@ def wsb_community(l_args):
d_submission = {}
l_watchlist_links = list()
psaw_api = PushshiftAPI()
# psaw_api = PushshiftAPI()
if ns_parser.b_new:
submissions = praw_api.subreddit("wallstreetbets").new(

View File

@@ -1,4 +1,3 @@
from gamestonk_terminal import config_terminal as cfg
import argparse
from gamestonk_terminal.sentiment import reddit_api
from gamestonk_terminal.sentiment import stocktwits_api

View File

@@ -1,14 +1,16 @@
import argparse
import requests
import pandas as pd
from gamestonk_terminal.helper_funcs import *
from gamestonk_terminal.helper_funcs import check_positive
# -------------------------------------------------------------------------------------------------------------------
def bullbear(l_args, s_ticker):
parser = argparse.ArgumentParser(
prog="bullbear",
description="""Print bullbear sentiment based on last 30 messages on the board.
Also prints the watchlist_count. [Source: Stocktwits]""",
description="""
Print bullbear sentiment based on last 30 messages on the board.
Also prints the watchlist_count. [Source: Stocktwits]
""",
)
parser.add_argument(
@@ -49,7 +51,8 @@ def bullbear(l_args, s_ticker):
print("Invalid symbol")
print("")
except:
except Exception as e:
print(e)
print("")
@@ -101,7 +104,8 @@ def messages(l_args, s_ticker):
print("Invalid symbol")
print("")
except:
except Exception as e:
print(e)
print("")
@@ -112,13 +116,13 @@ def trending(l_args):
)
try:
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
(_, l_unknown_args) = parser.parse_known_args(l_args)
if l_unknown_args:
print(f"The following args couldn't be interpreted: {l_unknown_args}\n")
return
result = requests.get(f"https://api.stocktwits.com/api/2/trending/symbols.json")
result = requests.get("https://api.stocktwits.com/api/2/trending/symbols.json")
if result.status_code == 200:
l_symbols = list()
for symbol in result.json()["symbols"]:
@@ -135,7 +139,8 @@ def trending(l_args):
print("Error!")
print("")
except:
except Exception as e:
print(e)
print("")
@@ -190,5 +195,6 @@ def stalker(l_args):
print("Invalid user")
print("")
except:
except Exception as e:
print(e)
print("")

View File

@@ -100,6 +100,7 @@ def inference(l_args, s_ticker):
# Percentage of confidence
if df_tweets["sentiment_estimation"].values[-1] > 0:
n_pos = df_tweets[df_tweets["prob_sen"] > 0]["prob_sen"].sum()
# pylint: disable=unused-variable
n_pct = round(100 * n_pos / df_tweets["probability"].sum())
else:
n_neg = abs(df_tweets[df_tweets["prob_sen"] < 0]["prob_sen"].sum())
@@ -361,7 +362,7 @@ def sentiment(l_args, s_ticker):
lw=3,
)
l_xticks.append(len(df_tweets))
datetime.strptime(dt_created, "%Y-%m-%d %H:%M:%S") + timedelta(days=1)
# (unused?) datetime.strptime(dt_created, "%Y-%m-%d %H:%M:%S") + timedelta(days=1)
l_xlabels.append(
datetime.strftime(
datetime.strptime(

View File

@@ -72,13 +72,13 @@ def load(l_args, s_ticker, s_start, s_interval, df_stock):
ts = TimeSeries(key=cfg.API_KEY_ALPHAVANTAGE, output_format="pandas")
# Daily
if s_interval == "1440min":
# pylint: disable unbalanced-tuple-unpacking
# pylint: disable=unbalanced-tuple-unpacking
df_stock, _ = ts.get_daily_adjusted(
symbol=ns_parser.s_ticker, outputsize="full"
)
# Intraday
else:
# pylint: disable unbalanced-tuple-unpacking
# pylint: disable=unbalanced-tuple-unpacking
df_stock, _ = ts.get_intraday(
symbol=ns_parser.s_ticker, outputsize="full", interval=s_interval
)
@@ -176,16 +176,17 @@ def view(l_args, s_ticker, s_start, s_interval, df_stock):
ts = TimeSeries(key=cfg.API_KEY_ALPHAVANTAGE, output_format="pandas")
# Daily
if s_interval == "1440min":
# pylint: disable unbalanced-tuple-unpacking
# pylint: disable=unbalanced-tuple-unpacking
df_stock, _ = ts.get_daily_adjusted(symbol=s_ticker, outputsize="full")
# Intraday
else:
# pylint: disable unbalanced-tuple-unpacking
# pylint: disable=unbalanced-tuple-unpacking
df_stock, _ = ts.get_intraday(
symbol=s_ticker, outputsize="full", interval=s_interval
)
except:
except Exception as e:
print(e)
print("Either the ticker or the API_KEY are invalids. Try again!")
return
@@ -201,6 +202,7 @@ def view(l_args, s_ticker, s_start, s_interval, df_stock):
if 4 not in ln_col_idx:
ln_col_idx.append(4)
# Check that the types given are not bigger than 4, as there are only 5 types (0-4)
# pylint: disable=len-as-condition
if len([i for i in ln_col_idx if i > 4]) > 0:
print("An index bigger than 4 was given, which is wrong. Try again")
return
@@ -214,6 +216,7 @@ def view(l_args, s_ticker, s_start, s_interval, df_stock):
else:
ln_col_idx = [int(x) - 1 for x in list(str(ns_parser.n_type))]
# Check that the types given are not bigger than 3, as there are only 4 types (0-3)
# pylint: disable=len-as-condition
if len([i for i in ln_col_idx if i > 3]) > 0:
print("An index bigger than 3 was given, which is wrong. Try again")
return
@@ -363,8 +366,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# SENTIMENT MARKET
elif ns_known_args.opt == "sen":
@@ -375,8 +378,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# RESEARCH MENU
elif ns_known_args.opt == "res":
@@ -387,8 +390,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# FUNDAMENTAL ANALYSIS MENU
elif ns_known_args.opt == "fa":
@@ -399,8 +402,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# TECHNICAL ANALYSIS MENU
elif ns_known_args.opt == "ta":
@@ -411,8 +414,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# DUE DILIGENCE MENU
elif ns_known_args.opt == "dd":
@@ -423,8 +426,8 @@ def main():
"Hope you made money today. Good bye my lover, good bye my friend.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
# PREDICTION TECHNIQUES
elif ns_known_args.opt == "pred":
@@ -435,7 +438,7 @@ def main():
else:
ts = TimeSeries(key=cfg.API_KEY_ALPHAVANTAGE, output_format="pandas")
# pylint: disable unbalanced-tuple-unpacking
# pylint: disable=unbalanced-tuple-unpacking
df_stock_pred, _ = ts.get_daily_adjusted(
symbol=s_ticker, outputsize="full"
)
@@ -451,8 +454,8 @@ def main():
"Hope you enjoyed the terminal. Remember that stonks only go up. Diamond hands.\n"
)
return
else:
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
else:
print("Shouldnt see this command!")