Several bugfixes and routines allowed multiple calls to same arg (#1513)

* several bugfixes and routines allowed multiple calls to same arg

* several bugfixes and routines allowed multiple calls to same arg

* minor fix
This commit is contained in:
didierlopes.eth
2022-03-19 01:57:41 +00:00
committed by GitHub
parent 28df1e0073
commit bb2e4c8a45
7 changed files with 142 additions and 54 deletions

View File

@@ -14,6 +14,7 @@ from gamestonk_terminal.decorators import check_api_key
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import (
EXPORT_BOTH_RAW_DATA_AND_FIGURES,
EXPORT_ONLY_RAW_DATA_ALLOWED,
check_non_negative,
check_positive,
@@ -541,7 +542,7 @@ class ComparisonAnalysisController(BaseController):
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-t")
ns_parser = parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
if self.similar and len(self.similar) > 1:
@@ -589,7 +590,9 @@ class ComparisonAnalysisController(BaseController):
)
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-t")
ns_parser = parse_known_args_and_warn(parser, other_args)
ns_parser = parse_known_args_and_warn(
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
if self.similar and len(self.similar) > 1:
yahoo_finance_view.display_correlation(
@@ -661,7 +664,7 @@ class ComparisonAnalysisController(BaseController):
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-s")
ns_parser = parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
if self.similar and len(self.similar) > 1:

View File

@@ -460,7 +460,7 @@ class DarkPoolShortsController(StockBaseController):
dest="raw",
)
ns_parser = parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
if self.ticker:

View File

@@ -208,7 +208,7 @@ class DueDiligenceController(StockBaseController):
other_args.insert(0, "-l")
ns_parser = parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
finnhub_view.rating_over_time(

View File

@@ -258,7 +258,7 @@ Ticker: [/param] {self.ticker} [cmds]
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)
if ns_parser:
yahoo_finance_view.display_info(self.ticker)
yahoo_finance_view.display_info(self.ticker, export=ns_parser.export)
@log_start_end(log=logger)
def call_mktcap(self, other_args: List[str]):
@@ -281,7 +281,9 @@ Ticker: [/param] {self.ticker} [cmds]
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
yahoo_finance_view.display_mktcap(self.ticker, start=ns_parser.start)
yahoo_finance_view.display_mktcap(
self.ticker, start=ns_parser.start, export=ns_parser.export
)
@log_start_end(log=logger)
def call_splits(self, other_args: List[str]):
@@ -296,7 +298,7 @@ Ticker: [/param] {self.ticker} [cmds]
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
)
if ns_parser:
yahoo_finance_view.display_splits(self.ticker)
yahoo_finance_view.display_splits(self.ticker, export=ns_parser.export)
@log_start_end(log=logger)
def call_shrs(self, other_args: List[str]):
@@ -313,7 +315,9 @@ Ticker: [/param] {self.ticker} [cmds]
)
if not self.suffix:
if ns_parser:
yahoo_finance_view.display_shareholders(self.ticker)
yahoo_finance_view.display_shareholders(
self.ticker, export=ns_parser.export
)
else:
console.print("Only US tickers are recognized.", "\n")
@@ -338,7 +342,9 @@ Ticker: [/param] {self.ticker} [cmds]
)
if not self.suffix:
if ns_parser:
yahoo_finance_view.display_sustainability(self.ticker)
yahoo_finance_view.display_sustainability(
self.ticker, export=ns_parser.export
)
else:
console.print("Only US tickers are recognized.", "\n")
@@ -359,7 +365,9 @@ Ticker: [/param] {self.ticker} [cmds]
)
if not self.suffix:
if ns_parser:
yahoo_finance_view.display_calendar_earnings(ticker=self.ticker)
yahoo_finance_view.display_calendar_earnings(
ticker=self.ticker, export=ns_parser.export
)
else:
console.print("Only US tickers are recognized.", "\n")

View File

@@ -52,12 +52,14 @@ def open_web(ticker: str):
@log_start_end(log=logger)
def display_info(ticker: str):
def display_info(ticker: str, export: str = ""):
"""Yahoo Finance ticker info
Parameters
----------
ticker : str
Fundamental analysis ticker symbol
export: str
Format to export data
"""
summary = ""
df_info = yahoo_finance_model.get_info(ticker)
@@ -75,20 +77,25 @@ def display_info(ticker: str):
else:
logger.error("Invalid data")
console.print("[red]Invalid data[/red]\n")
return
if summary:
console.print("Business Summary:")
console.print(summary)
console.print("")
export_data(export, os.path.dirname(os.path.abspath(__file__)), "info", df_info)
@log_start_end(log=logger)
def display_shareholders(ticker: str):
def display_shareholders(ticker: str, export: str = ""):
"""Yahoo Finance ticker shareholders
Parameters
----------
ticker : str
Fundamental analysis ticker symbol
export: str
Format to export data
"""
(
df_major_holders,
@@ -113,16 +120,38 @@ def display_shareholders(ticker: str):
)
console.print()
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"major_holders",
df_major_holders,
)
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"institutional_holders",
df_institutional_shareholders,
)
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"mutualfunds_holders",
df_major_holders,
)
@log_start_end(log=logger)
def display_sustainability(ticker: str):
def display_sustainability(ticker: str, export: str = ""):
"""Yahoo Finance ticker sustainability
Parameters
----------
other_args : List[str]
argparse other args
ticker : str
Fundamental analysis ticker symbol
export: str
Format to export data
"""
df_sustainability = yahoo_finance_model.get_sustainability(ticker)
@@ -143,14 +172,21 @@ def display_sustainability(ticker: str):
logger.error("Invalid data")
console.print("[red]Invalid data[/red]\n")
export_data(
export, os.path.dirname(os.path.abspath(__file__)), "sust", df_sustainability
)
@log_start_end(log=logger)
def display_calendar_earnings(ticker: str):
def display_calendar_earnings(ticker: str, export: str = ""):
"""Yahoo Finance ticker calendar earnings
Parameters
----------
ticker : str
Fundamental analysis ticker symbol
export: str
Format to export data
"""
df_calendar = yahoo_finance_model.get_calendar_earnings(ticker).T
if df_calendar.empty:
@@ -164,6 +200,8 @@ def display_calendar_earnings(ticker: str):
)
console.print("")
export_data(export, os.path.dirname(os.path.abspath(__file__)), "cal", df_calendar)
@log_start_end(log=logger)
def display_dividends(

74
routines/example_with_inputs_saved.gst vendored Normal file
View File

@@ -0,0 +1,74 @@
# Select location folder to export data to (if doesn't exist, will be created by default)
export didier_analysis_on_$ARGV[0]
# Go into the stocks context
stocks
# Load a ticker that's given as a first argument of the routine
load $ARGV[0]
# Go into the Sector and Industry analysis
sia
# When filtering by industry peers remove market cap filtering
clear mktcap
# Compare ticker against industry peers regarding their revenues over time
vis re --export jpg
# Filter by large market cap
mktcap Large
# Compare industry peers (with large market cap) regarding their current quick ratio
metric qr --export jpg
# Take these companies to Comparison Analysis menu
ca
# Access these companies historical raw price since 2019
historical -s 2019-01-01 -n --export jpg
# Compute their correlation of price
hcorr -s 2019-01-01 --export jpg
# Compare their income statements for current year
income --export csv
# Go back one menu to the main stocks context
..
# Enter in the Dark Pool short menu
dps
# Shows stock price vs short interest volume
psi --export jpg,csv
# Go back one menu and go into Behavioural Analysis menu
../ba
# Check interest on google search of covid and quarantine correlated with ticker price
interest -s 2019-01-01 -w covid,quarantine --export interest_with_covid_quarantine.jpg
# Correlate headlines news sentiment with stock price
snews --export jpg
# Check shareholders of company (leave menu, go into Fundamental Analysis command and call command)
../fa/shrs --export csv
# Get SEC filings
../dd/sec --export csv
# Analyst ratings over time
rot --export jpg
# Price targets over time vs stock price
pt --export jpg
# Apply Relative Strength Index to the stock price
../ta/rsi --export jpg
# Get similar companies arccording to Finnhub API
../ca/getfinnhub
# Compare their volume
volume --export jpg

View File

@@ -377,29 +377,10 @@ class TerminalController(BaseController):
lines = list()
idx = 0
for rawline in raw_lines:
arg_to_replace = f"$ARGV[{idx}]"
templine = rawline
while arg_to_replace in rawline:
if idx > (len(ns_parser_exe.routine_args) - 1):
console.print(
"[red]There are more arguments on the routine "
".gst file than input args provided[/red]"
)
return
templine = templine.replace(
arg_to_replace, ns_parser_exe.routine_args[idx]
)
idx += 1
arg_to_replace = f"$ARGV[{idx}]"
for i, arg in enumerate(ns_parser_exe.routine_args):
templine = templine.replace(f"$ARGV[{i}]", arg)
lines.append(templine)
if idx < len(ns_parser_exe.routine_args):
console.print(
"[red]There are more inputs provided than the number "
"of arguments on routine .gst file\n[/red]"
)
else:
lines = raw_lines
@@ -652,27 +633,11 @@ def run_scripts(
if routines_args:
lines = list()
idx = 0
for rawline in raw_lines:
arg_to_replace = f"$ARGV[{idx}]"
templine = rawline
while arg_to_replace in rawline:
if idx > (len(routines_args) - 1):
console.print(
"[red]There are more arguments on the routine .gst file than input args provided[/red]"
)
return
templine = templine.replace(arg_to_replace, routines_args[idx])
idx += 1
arg_to_replace = f"$ARGV[{idx}]"
for i, arg in enumerate(routines_args):
templine = templine.replace(f"$ARGV[{i}]", arg)
lines.append(templine)
if idx < len(routines_args):
console.print(
"[red]There are more inputs provided than the number of arguments on routine .gst file\n[/red]"
)
else:
lines = raw_lines