From b83fe243d281ef3aebbaf6cb2e18ce22930e626b Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Wed, 3 Mar 2021 23:03:57 -0800 Subject: [PATCH] Fix FA Business Insider parsing and fix a bug where Business Insider does not management info for a ticker --- .../business_insider_api.py | 19 +++++++++++++++++-- .../tests/test_fa_business_insider_api.py | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100755 gamestonk_terminal/tests/test_fa_business_insider_api.py diff --git a/gamestonk_terminal/fundamental_analysis/business_insider_api.py b/gamestonk_terminal/fundamental_analysis/business_insider_api.py index 2deb5283301..95e48fcb72d 100644 --- a/gamestonk_terminal/fundamental_analysis/business_insider_api.py +++ b/gamestonk_terminal/fundamental_analysis/business_insider_api.py @@ -33,8 +33,23 @@ def management(l_args, s_ticker): "lxml", ) + found_h2s = dict() + + for next_h2 in text_soup_market_business_insider.findAll( + "h2", {"class": "header-underline"} + ): + next_table = next_h2.find_next_sibling("table", {"class": "table"}) + + if next_table: + found_h2s[next_h2.text] = next_table + + if found_h2s.get("Management") is None: + print(f"No management information in Business Insider for {s_ticker}") + print("") + return + l_titles = list() - for s_title in text_soup_market_business_insider.findAll( + for s_title in found_h2s["Management"].findAll( "td", {"class": "table__td text-right"} ): if any(c.isalpha() for c in s_title.text.strip()) and ( @@ -43,7 +58,7 @@ def management(l_args, s_ticker): l_titles.append(s_title.text.strip()) l_names = list() - for s_name in text_soup_market_business_insider.findAll( + for s_name in found_h2s["Management"].findAll( "td", {"class": "table__td table--allow-wrap"} ): l_names.append(s_name.text.strip()) diff --git a/gamestonk_terminal/tests/test_fa_business_insider_api.py b/gamestonk_terminal/tests/test_fa_business_insider_api.py new file mode 100755 index 00000000000..3acb98dc937 --- /dev/null +++ b/gamestonk_terminal/tests/test_fa_business_insider_api.py @@ -0,0 +1,13 @@ +""" fundamental_analysis/business_insider_api.py tests """ +# noqa: F401 +import unittest + +# pylint: disable=unused-import +import pytest + +from gamestonk_terminal.fundamental_analysis.business_insider_api import management + + +class TestFaBusinessInsiderApi(unittest.TestCase): + def test_management(self): + management([], "PLTR")