diff --git a/isthisstockgood/Active/Zacks.py b/isthisstockgood/Active/Zacks.py index 826aa92..b32df44 100644 --- a/isthisstockgood/Active/Zacks.py +++ b/isthisstockgood/Active/Zacks.py @@ -28,5 +28,13 @@ def get_growth_rate(self, text): if "Next 5 Years" in line: result = lines[i+1] + if "NA" not in result: + estimate = re.sub(r"[^\d\.]", "", result) + return float(estimate) + + for i, line in enumerate(lines): + if "Next Year (" in line: + result = lines[i+1] + estimate = re.sub(r"[^\d\.]", "", result) return float(estimate) diff --git a/isthisstockgood/DataFetcher.py b/isthisstockgood/DataFetcher.py index ed1651a..2fb5685 100644 --- a/isthisstockgood/DataFetcher.py +++ b/isthisstockgood/DataFetcher.py @@ -55,8 +55,14 @@ def fetchDataForTickerSymbol(ticker): zacks_analysis = data_fetcher.zacks_analysis # NOTE: Some stocks won't have analyst growth rates, such as newly listed stocks or some foreign stocks. five_year_growth_rate = \ - yahoo_finance_analysis.five_year_growth_rate if yahoo_finance_analysis \ - else zacks_analysis.five_year_growth_rate if zacks_analysis \ + yahoo_finance_analysis.five_year_growth_rate if ( + yahoo_finance_analysis + and yahoo_finance_analysis.five_year_growth_rate + ) \ + else zacks_analysis.five_year_growth_rate if ( + zacks_analysis + and zacks_analysis.five_year_growth_rate + ) \ else 0 margin_of_safety_price, sticker_price = _calculateMarginOfSafetyPrice( msn_money.equity_growth_rates[-1], diff --git a/isthisstockgood/server.py b/isthisstockgood/server.py index 800b514..7eb0a19 100644 --- a/isthisstockgood/server.py +++ b/isthisstockgood/server.py @@ -19,9 +19,9 @@ def get_logger(): def create_app(fetchDataForTickerSymbol): app = Flask(__name__) - @app.route('/api/ticker/nvda') - def api_ticker(): - template_values = fetchDataForTickerSymbol("NVDA") + @app.route('/api/ticker/') + def api_ticker(ticker): + template_values = fetchDataForTickerSymbol(ticker) if not template_values: data = render_template('json/error.json', **{'error' : 'Invalid ticker symbol'}) diff --git a/tests/test_DataSources.py b/tests/test_DataSources.py index cff3837..6558c48 100644 --- a/tests/test_DataSources.py +++ b/tests/test_DataSources.py @@ -4,7 +4,7 @@ def test_msn_money(): test_ticker = 'MSFT' - test_name = 'Microsoft Corp' + test_name = 'Microsoft Corporation' data = get_msn_money_data(test_ticker) diff --git a/tests/test_Zacks.py b/tests/test_Zacks.py new file mode 100644 index 0000000..8b892ea --- /dev/null +++ b/tests/test_Zacks.py @@ -0,0 +1,4 @@ +from isthisstockgood.Active.Zacks import Zacks + +def test_zacks(): + zacks = Zacks("TSLA")