Bug fixes

Remove "is True" statements (unnecessary for if functions)
Add 5 second timeout for internet connection test
This commit is contained in:
Andrew Dinh 2019-09-08 22:16:46 -07:00 committed by GitHub
parent 41650d0f92
commit d1f3d594b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

36
main.py
View File

@ -317,7 +317,7 @@ class Stock:
# Sometimes close value is a None value # Sometimes close value is a None value
i = 0 i = 0
while i < len(listYahoo[1]): while i < len(listYahoo[1]):
if Functions.listIndexExists(listYahoo[1][i]) is True: if Functions.listIndexExists(listYahoo[1][i]):
if listYahoo[1][i] is None: if listYahoo[1][i] is None:
del listYahoo[1][i] del listYahoo[1][i]
del listYahoo[0][i] del listYahoo[0][i]
@ -723,7 +723,7 @@ class Stock:
break break
if marketCap == 0: if marketCap == 0:
somethingWrong = True somethingWrong = True
if somethingWrong is True: if somethingWrong:
ticker = self.name ticker = self.name
yahoo_financials = YahooFinancials(ticker) yahoo_financials = YahooFinancials(ticker)
marketCap = yahoo_financials.get_market_cap() marketCap = yahoo_financials.get_market_cap()
@ -810,7 +810,7 @@ class Stock:
indicatorValue = str( indicatorValue = str(
input(Stock.indicator + ' of ' + self.name + ': ')) input(Stock.indicator + ' of ' + self.name + ': '))
if Functions.strintIsFloat(indicatorValue) is True: if Functions.strintIsFloat(indicatorValue):
indicatorValueFound = True indicatorValueFound = True
return float(indicatorValue) return float(indicatorValue)
else: else:
@ -850,7 +850,7 @@ def benchmarkInit():
benchmark = str(input('Please choose a benchmark from the list: ')) benchmark = str(input('Please choose a benchmark from the list: '))
# benchmark = 'SPY' # TESTING # benchmark = 'SPY' # TESTING
if Functions.stringIsInt(benchmark) is True: if Functions.stringIsInt(benchmark):
if int(benchmark) <= len(benchmarks) and int(benchmark) > 0: if int(benchmark) <= len(benchmarks) and int(benchmark) > 0:
benchmarkInt = int(benchmark) benchmarkInt = int(benchmark)
benchmark = benchmarks[benchmarkInt-1] benchmark = benchmarks[benchmarkInt-1]
@ -896,7 +896,7 @@ def stocksInit():
print('[' + str(i+1) + '] ' + methods[i]) print('[' + str(i+1) + '] ' + methods[i])
while method == 0 or method > len(methods): while method == 0 or method > len(methods):
method = str(input('Which method? ')) method = str(input('Which method? '))
if Functions.stringIsInt(method) is True: if Functions.stringIsInt(method):
method = int(method) method = int(method)
if method == 0 or method > len(methods): if method == 0 or method > len(methods):
print('Please choose a number from 1 to', len(methods)) print('Please choose a number from 1 to', len(methods))
@ -924,11 +924,11 @@ def stocksInit():
print('[' + str(i+1) + '] ' + listOfFiles[i]) print('[' + str(i+1) + '] ' + listOfFiles[i])
while stocksFound is False: while stocksFound is False:
fileName = str(input('What is the file number/name? ')) fileName = str(input('What is the file number/name? '))
if Functions.stringIsInt(fileName) is True: if Functions.stringIsInt(fileName):
if int(fileName) < len(listOfFiles)+1 and int(fileName) > 0: if int(fileName) < len(listOfFiles)+1 and int(fileName) > 0:
fileName = listOfFiles[int(fileName)-1] fileName = listOfFiles[int(fileName)-1]
print(fileName) print(fileName)
if Functions.fileExists(fileName) is True: if Functions.fileExists(fileName):
listOfStocks = [] listOfStocks = []
file = open(fileName, 'r') file = open(fileName, 'r')
n = file.read() n = file.read()
@ -954,7 +954,7 @@ def stocksInit():
while isInteger is False: while isInteger is False:
temp = input('Number of stocks to analyze (2 minimum): ') temp = input('Number of stocks to analyze (2 minimum): ')
isInteger = Functions.stringIsInt(temp) isInteger = Functions.stringIsInt(temp)
if isInteger is True: if isInteger:
if int(temp) >= 2: if int(temp) >= 2:
numberOfStocks = int(temp) numberOfStocks = int(temp)
else: else:
@ -1162,7 +1162,7 @@ def timeFrameInit():
'Please enter the time frame in months (<60 recommended):', end='') 'Please enter the time frame in months (<60 recommended):', end='')
temp = input(' ') temp = input(' ')
isInteger = Functions.stringIsInt(temp) isInteger = Functions.stringIsInt(temp)
if isInteger is True: if isInteger:
if int(temp) > 1 and int(temp) < 1000: if int(temp) > 1 and int(temp) < 1000:
months = int(temp) months = int(temp)
elif int(temp) >= 1000: elif int(temp) >= 1000:
@ -1328,7 +1328,7 @@ def indicatorInit():
# indicator = 'expense ratio' # TESTING # indicator = 'expense ratio' # TESTING
if Functions.stringIsInt(indicator) is True: if Functions.stringIsInt(indicator):
if int(indicator) <= 4 and int(indicator) > 0: if int(indicator) <= 4 and int(indicator) > 0:
indicator = listOfIndicators[int(indicator)-1] indicator = listOfIndicators[int(indicator)-1]
indicatorFound = True indicatorFound = True
@ -1386,7 +1386,7 @@ def calcIndicatorRegression(listOfIndicatorValues, listOfReturns):
regression.append(b[1]) regression.append(b[1])
regressionList.append(regression) regressionList.append(regression)
if Stock.plotIndicatorRegression is True: if Stock.plotIndicatorRegression:
plot_regression_line(x, y, b, i) plot_regression_line(x, y, b, i)
return regressionList return regressionList
@ -1449,7 +1449,7 @@ def persistenceTimeFrame():
while persTimeFrameFound is False: while persTimeFrameFound is False:
persistenceTimeFrame = str( persistenceTimeFrame = str(
input('Please choose how many months to measure persistence: ')) input('Please choose how many months to measure persistence: '))
if Functions.stringIsInt(persistenceTimeFrame) is True: if Functions.stringIsInt(persistenceTimeFrame):
if int(persistenceTimeFrame) > 0 and int(persistenceTimeFrame) < Stock.timeFrame - 1: if int(persistenceTimeFrame) > 0 and int(persistenceTimeFrame) < Stock.timeFrame - 1:
persistenceTimeFrame = int(persistenceTimeFrame) persistenceTimeFrame = int(persistenceTimeFrame)
persTimeFrameFound = True persTimeFrameFound = True
@ -1508,7 +1508,7 @@ def indicatorMain(listOfStocks):
print('') print('')
# Remove outliers # Remove outliers
if Stock.removeOutliers is True: if Stock.removeOutliers:
cprint('\nRemoving outliers\n', 'white', attrs=['underline']) cprint('\nRemoving outliers\n', 'white', attrs=['underline'])
temp = Functions.removeOutliers(listOfStocksIndicatorValues) temp = Functions.removeOutliers(listOfStocksIndicatorValues)
if temp[0] == listOfStocksIndicatorValues: if temp[0] == listOfStocksIndicatorValues:
@ -1602,7 +1602,7 @@ def continueProgram():
def plotIndicatorRegression(): def plotIndicatorRegression():
if Functions.detectDisplay() is True: if Functions.detectDisplay():
if Functions.checkPackage('matplotlib') is False: if Functions.checkPackage('matplotlib') is False:
print( print(
'matplotlib is not installed. \nIf you would like to install' + 'matplotlib is not installed. \nIf you would like to install' +
@ -1612,7 +1612,7 @@ def plotIndicatorRegression():
print('\nWould you like to plot indicator linear regression ' print('\nWould you like to plot indicator linear regression '
'results?') 'results?')
plotLinear = Functions.trueOrFalse() plotLinear = Functions.trueOrFalse()
if plotLinear is True: if plotLinear:
Stock.plotIndicatorRegression = True Stock.plotIndicatorRegression = True
else: else:
Stock.plotIndicatorRegression = False Stock.plotIndicatorRegression = False
@ -1622,12 +1622,12 @@ def plotIndicatorRegression():
# Ask for how long # Ask for how long
Stock.timePlotIndicatorRegression = 60 Stock.timePlotIndicatorRegression = 60
''' '''
if Stock.plotIndicatorRegression is True: if Stock.plotIndicatorRegression:
timeFound = False timeFound = False
print('') print('')
while timeFound is False: while timeFound is False:
x = str(input('How long would you like to keep the graph up (seconds)? ')) x = str(input('How long would you like to keep the graph up (seconds)? '))
if Functions.stringIsInt(x) is True: if Functions.stringIsInt(x):
if int(x) > 0: if int(x) > 0:
Stock.timePlotIndicatorRegression = int(x) Stock.timePlotIndicatorRegression = int(x)
timeFound = True timeFound = True
@ -1647,7 +1647,7 @@ def main():
Stock.config = checkConfig('config.json') Stock.config = checkConfig('config.json')
runningProgram = True runningProgram = True
while runningProgram is True: while runningProgram:
if Stock.config == 'N/A': if Stock.config == 'N/A':
# Check that all required packages are installed # Check that all required packages are installed
packagesInstalled = Functions.checkPackages( packagesInstalled = Functions.checkPackages(