From 28d7b8ffadac066e710bac641e0d199a868918b0 Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Fri, 26 Feb 2021 23:24:22 -0800 Subject: [PATCH] Fixing low_float --- .../discovery/short_interest_api.py | 45 ++++++++----------- .../test_discovery_short_interest_api.py | 8 +++- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/gamestonk_terminal/discovery/short_interest_api.py b/gamestonk_terminal/discovery/short_interest_api.py index 29cd1af82a9..998d97807e5 100644 --- a/gamestonk_terminal/discovery/short_interest_api.py +++ b/gamestonk_terminal/discovery/short_interest_api.py @@ -44,11 +44,6 @@ def high_short_interest(l_args): requests.get(url_high_short_interested_stocks).text, "lxml" ) - # print(text_soup_high_short_interested_stocks.text) - # html = text_soup_high_short_interested_stocks.prettify("utf-8") - # stock_list = text_soup_high_short_interested_stocks.find_all("td") - # stock_list_tr = text_soup_high_short_interested_stocks.find_all("tr") - a_high_short_interest_header = list() for high_short_interest_header in text_soup_high_short_interested_stocks.findAll( "td", {"class": "tblhdr"} @@ -86,12 +81,13 @@ def high_short_interest(l_args): def low_float(l_args): parser = argparse.ArgumentParser( prog="low_float", - description="""Print top stocks with lowest float. LowFloat.com provides a convenient - sorted database of stocks which have a float of under 10 million shares. Additional key - data such as the number of outstanding shares, short interest, and company industry is - displayed. Data is presented for the Nasdaq Stock Market, the New York Stock Exchange, - the American Stock Exchange, and the Over the Counter Bulletin Board. - [Source: www.lowfloat.com]""", + description=""" + Print top stocks with lowest float. LowFloat.com provides a convenient + sorted database of stocks which have a float of under 10 million shares. Additional key + data such as the number of outstanding shares, short interest, and company industry is + displayed. Data is presented for the Nasdaq Stock Market, the New York Stock Exchange, + the American Stock Exchange, and the Over the Counter Bulletin Board. [Source: www.lowfloat.com] + """, ) parser.add_argument( @@ -126,26 +122,21 @@ def low_float(l_args): df_low_float = pd.DataFrame(columns=a_low_float_header) df_low_float.loc[0] = ["", "", "", "", "", "", ""] - a_low_float_stocks = re.sub( - "", - "", - text_soup_low_float_stocks.find_all("td")[3].text, - flags=re.DOTALL, - ).split("\n")[2:] - a_low_float_stocks[0] = a_low_float_stocks[0].replace( - "TickerCompanyExchangeFloatOutstdShortIntIndustry", "" - ) + stock_list_tr = text_soup_low_float_stocks.find_all("tr") - l_stock_info = list() - for elem in a_low_float_stocks: - if elem is "": + low_float_data = list() + for a_stock in stock_list_tr: + a_stock_txt = a_stock.text + + if a_stock_txt == "": continue - l_stock_info.append(elem) + low_float_data = a_stock_txt.split("\n") - if len(l_stock_info) == 7: - df_low_float.loc[len(df_low_float.index)] = l_stock_info - l_stock_info = list() + if len(low_float_data) == 8: + df_low_float.loc[len(df_low_float.index)] = low_float_data[:-1] + + low_float_data = list() pd.set_option("display.max_colwidth", -1) print(df_low_float.head(n=ns_parser.n_num).to_string(index=False)) diff --git a/gamestonk_terminal/tests/test_discovery_short_interest_api.py b/gamestonk_terminal/tests/test_discovery_short_interest_api.py index f577b58cc03..b17f3aa238a 100755 --- a/gamestonk_terminal/tests/test_discovery_short_interest_api.py +++ b/gamestonk_terminal/tests/test_discovery_short_interest_api.py @@ -5,9 +5,15 @@ import unittest # pylint: disable=unused-import import pytest -from gamestonk_terminal.discovery.short_interest_api import high_short_interest +from gamestonk_terminal.discovery.short_interest_api import ( + high_short_interest, + low_float, +) class TestDiscoveryShortInterestApi(unittest.TestCase): def test_high_short_interest(self): high_short_interest(["-n", "10"]) + + def test_low_float(self): + low_float(["-n", "10"])