diff --git a/docs/conf.py b/docs/conf.py index fecf2ce..6865c23 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Tianning Li' # The full version, including alpha/beta/rc tags -release = '0.12.2' +release = '0.13.0' # -- General configuration --------------------------------------------------- diff --git a/finvizfinance/__init__.py b/finvizfinance/__init__.py index 35d4c4c..2322b10 100644 --- a/finvizfinance/__init__.py +++ b/finvizfinance/__init__.py @@ -5,5 +5,5 @@ .. moduleauthor:: Tianning Li """ -__version__ = "0.12.2" +__version__ = "0.13.0" __author__ = "Tianning Li" diff --git a/finvizfinance/crypto.py b/finvizfinance/crypto.py index e0cfb39..cf41d65 100644 --- a/finvizfinance/crypto.py +++ b/finvizfinance/crypto.py @@ -7,16 +7,20 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 5 + class Crypto: """Crypto Getting information from the finviz crypto page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" - pass + self._screener_table_index = screener_table_index def performance(self): """Get crypto performance table. @@ -25,7 +29,7 @@ def performance(self): df(pandas.DataFrame): crypto performance table """ url = "https://finviz.com/crypto_performance.ashx" - df = scrap_function(url) + df = scrap_function(url, self._screener_table_index) return df def chart(self, crypto, timeframe="D", urlonly=False): diff --git a/finvizfinance/forex.py b/finvizfinance/forex.py index 5994737..e4c4dbc 100644 --- a/finvizfinance/forex.py +++ b/finvizfinance/forex.py @@ -7,15 +7,20 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 5 + class Forex: """Forex Getting information from the finviz forex page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" - pass + self._screener_table_index = screener_table_index def performance(self, change="percent"): """Get forex performance table. @@ -33,7 +38,7 @@ def performance(self, change="percent"): url = "https://finviz.com/forex_performance.ashx?v=1&tv=2&o=-perfdaypct" else: raise ValueError("Options of change: percent(default), PIPS") - df = scrap_function(url) + df = scrap_function(url, self._screener_table_index) return df def chart(self, forex, timeframe="D", urlonly=False): diff --git a/finvizfinance/group/custom.py b/finvizfinance/group/custom.py index 25d427c..34ec235 100644 --- a/finvizfinance/group/custom.py +++ b/finvizfinance/group/custom.py @@ -40,14 +40,20 @@ 26: "Number of Stocks", } +SCREENER_TABLE_INDEX = 8 + class Custom(Overview): """Custom inherit from overview module. Getting information from the finviz group custom page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = "https://finviz.com/groups.ashx?{group}&v=152" self.url = self.BASE_URL.format(group="g=sector") Overview._load_setting(self) @@ -85,7 +91,7 @@ def screener_view( self.url += "&c=" + ",".join(columns) soup = web_scrap(self.url) - table = soup.findAll("table")[6] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") table_header = [i.text for i in rows[0].findAll("td")][1:] df = pd.DataFrame([], columns=table_header) diff --git a/finvizfinance/group/overview.py b/finvizfinance/group/overview.py index 699bb5d..353c0de 100644 --- a/finvizfinance/group/overview.py +++ b/finvizfinance/group/overview.py @@ -9,14 +9,20 @@ """ +SCREENER_TABLE_INDEX = 7 + class Overview: """Overview Getting information from the finviz group overview page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = "https://finviz.com/groups.ashx?{group}&v=110" self.url = self.BASE_URL.format(group="g=sector") self._load_setting() @@ -82,7 +88,7 @@ def screener_view(self, group="Sector", order="Name"): ) soup = web_scrap(self.url) - table = soup.findAll("table")[5] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") table_header = [i.text for i in rows[0].findAll("td")][1:] df = pd.DataFrame([], columns=table_header) diff --git a/finvizfinance/group/performance.py b/finvizfinance/group/performance.py index 5da9aed..fcebb0a 100644 --- a/finvizfinance/group/performance.py +++ b/finvizfinance/group/performance.py @@ -7,14 +7,20 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 7 + class Performance(Overview): """Performance inherit from overview module. Getting information from the finviz group performance page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = "https://finviz.com/groups.ashx?{group}&v=140" self.url = self.BASE_URL.format(group="g=sector") Overview._load_setting(self) diff --git a/finvizfinance/group/valuation.py b/finvizfinance/group/valuation.py index fb31233..1e90828 100644 --- a/finvizfinance/group/valuation.py +++ b/finvizfinance/group/valuation.py @@ -6,15 +6,20 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 7 class Valuation(Overview): """Valuation inherit from overview module. Getting information from the finviz group valuation page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = "https://finviz.com/groups.ashx?{group}&v=120" self.url = self.BASE_URL.format(group="g=sector") Overview._load_setting(self) diff --git a/finvizfinance/insider.py b/finvizfinance/insider.py index 1bbd65d..908cfc3 100644 --- a/finvizfinance/insider.py +++ b/finvizfinance/insider.py @@ -9,6 +9,7 @@ """ INSIDER_URL = "https://finviz.com/insidertrading.ashx" +INSIDER_TABLE_INDEX = 6 class Insider: @@ -19,10 +20,12 @@ class Insider: option (str): choose a option (latest, latest buys, latest sales, top week, top week buys, top week sales, top owner trade, top owner buys, top owner sales, insider_id) + ticker_fundament_table_index(int): table index of the insider. change only if change on finviz side. """ - def __init__(self, option="latest"): + def __init__(self, option="latest", insider_table_index=INSIDER_TABLE_INDEX): """initiate module""" + self._insider_table_index = insider_table_index if option == "latest": self.soup = web_scrap(INSIDER_URL) elif option == "latest buys": @@ -63,7 +66,7 @@ def get_insider(self): Returns: df(pandas.DataFrame): insider information table """ - insider_trader = self.soup.findAll("table")[4] + insider_trader = self.soup.findAll("table")[self._insider_table_index] rows = insider_trader.findAll("tr") table_header = [i.text.strip() for i in rows[0].findAll("td")] + [ "SEC Form 4 Link" diff --git a/finvizfinance/news.py b/finvizfinance/news.py index b1fe171..dad2905 100644 --- a/finvizfinance/news.py +++ b/finvizfinance/news.py @@ -9,19 +9,23 @@ """ NEWS_URL = "https://finviz.com/news.ashx" +NEWS_TABLE_INDEX = 8 class News: """News Getting information from the finviz news page. + Args: + news_table_index(int): table index of the news page. change only if change on finviz side. """ - def __init__(self): + def __init__(self, news_table_index=NEWS_TABLE_INDEX): """initiate module""" self.all_news = {} self.soup = web_scrap(NEWS_URL) self.news = {} + self._news_table_index = news_table_index def get_news(self): """Get insider information table. @@ -33,9 +37,9 @@ def get_news(self): """ tables = self.soup.findAll("table") - news = tables[6] + news = tables[self._news_table_index] news_df = self._get_news_helper(news) - blog = tables[7] + blog = tables[self._news_table_index + 1] blog_df = self._get_news_helper(blog) self.news = {"news": news_df, "blogs": blog_df} return self.news diff --git a/finvizfinance/quote.py b/finvizfinance/quote.py index e4ec9f7..ebf2746 100644 --- a/finvizfinance/quote.py +++ b/finvizfinance/quote.py @@ -21,6 +21,7 @@ "EPS nest Y", "Insider ", ] +TICKER_FUNDAMENT_TABLE_INDEX = 6 class Quote: @@ -46,10 +47,18 @@ class finvizfinance: Args: ticker(str): ticker string verbose(int): choice of visual the progress. 1 for visualize progress. + ticker_fundament_table_index(int): table index of the stock fundamental. change only if change on finviz side. """ - def __init__(self, ticker, verbose=0): + def __init__( + self, + ticker, + verbose=0, + ticker_fundament_table_index=TICKER_FUNDAMENT_TABLE_INDEX, + ): """initiate module""" + self._ticker_fundament_table_index = ticker_fundament_table_index + self.ticker = ticker self.flag = False self.quote_url = QUOTE_URL.format(ticker=ticker) @@ -118,7 +127,7 @@ def ticker_fundament(self, raw=True): """ fundament_info = {} - table = self.soup.findAll("table")[4] + table = self.soup.findAll("table")[self._ticker_fundament_table_index] rows = table.findAll("tr") fundament_info["Company"] = rows[1].text @@ -334,9 +343,12 @@ def ticker_signal(self): ] ticker_signal = [] for signal in signals: - fticker.set_filter(signal=signal, ticker=self.ticker.upper()) - if fticker.screener_view(verbose=0) == [self.ticker.upper()]: - ticker_signal.append(signal) + try: + fticker.set_filter(signal=signal, ticker=self.ticker.upper()) + if fticker.screener_view(verbose=0) == [self.ticker.upper()]: + ticker_signal.append(signal) + except: + pass return ticker_signal def ticker_full_info(self): diff --git a/finvizfinance/screener/custom.py b/finvizfinance/screener/custom.py index 75546cc..8e993bf 100644 --- a/finvizfinance/screener/custom.py +++ b/finvizfinance/screener/custom.py @@ -84,14 +84,21 @@ 70: "IPO Date", } +SCREENER_TABLE_INDEX = 21 + class Custom(Overview): """Custom inherit from overview module. Getting information from the finviz screener custom page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=151{signal}{filter}&ft=4{ticker}" ) @@ -182,7 +189,7 @@ def screener_view( else: progress_bar(1, 1) - table = soup.findAll("table")[19] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") table_header = [i.text for i in rows[0].findAll("td")][1:] num_col_index = [table_header.index(i) for i in table_header if i in NUMBER_COL] @@ -209,7 +216,7 @@ def screener_view( url = url.replace("o=", "o=-") url += "&c=" + ",".join(columns) soup = web_scrap(url) - table = soup.findAll("table")[19] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") df = self._screener_helper( i, page, rows, df, num_col_index, table_header, limit diff --git a/finvizfinance/screener/financial.py b/finvizfinance/screener/financial.py index 3a54294..b82b23d 100644 --- a/finvizfinance/screener/financial.py +++ b/finvizfinance/screener/financial.py @@ -7,14 +7,21 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Financial(Overview): """Financial inherit from overview module. Getting information from the finviz screener financial page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=161{signal}{filter}&ft=4{ticker}" ) diff --git a/finvizfinance/screener/overview.py b/finvizfinance/screener/overview.py index d8bc3a1..2906c10 100644 --- a/finvizfinance/screener/overview.py +++ b/finvizfinance/screener/overview.py @@ -17,14 +17,20 @@ """ +SCREENER_TABLE_INDEX = 21 + class Overview: """Overview Getting information from the finviz screener overview page. + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=111{signal}{filter}&ft=4{ticker}" ) @@ -254,7 +260,7 @@ def screener_view( else: progress_bar(1, 1) - table = soup.findAll("table")[19] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") table_header = [i.text for i in rows[0].findAll("td")][1:] num_col_index = [table_header.index(i) for i in table_header if i in NUMBER_COL] @@ -280,7 +286,7 @@ def screener_view( if not ascend: url = url.replace("o=", "o=-") soup = web_scrap(url) - table = soup.findAll("table")[19] + table = soup.findAll("table")[self._screener_table_index] rows = table.findAll("tr") df = self._screener_helper( i, page, rows, df, num_col_index, table_header, limit diff --git a/finvizfinance/screener/ownership.py b/finvizfinance/screener/ownership.py index 6db558d..9da49bd 100644 --- a/finvizfinance/screener/ownership.py +++ b/finvizfinance/screener/ownership.py @@ -7,14 +7,21 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Ownership(Overview): """Ownership inherit from overview module. Getting information from the finviz screener ownership page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=131{signal}{filter}&ft=4{ticker}" ) diff --git a/finvizfinance/screener/performance.py b/finvizfinance/screener/performance.py index df5ec86..540acfb 100644 --- a/finvizfinance/screener/performance.py +++ b/finvizfinance/screener/performance.py @@ -7,14 +7,21 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Performance(Overview): """Performance inherit from overview module. Getting information from the finviz screener performance page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=141{signal}{filter}&ft=4{ticker}" ) diff --git a/finvizfinance/screener/technical.py b/finvizfinance/screener/technical.py index 0d005e3..58c916a 100644 --- a/finvizfinance/screener/technical.py +++ b/finvizfinance/screener/technical.py @@ -7,14 +7,21 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Technical(Overview): """Technical inherit from overview module. Getting information from the finviz screener technical page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=171{signal}{filter}&ft=4{ticker}" ) diff --git a/finvizfinance/screener/ticker.py b/finvizfinance/screener/ticker.py index 0bffb99..554bc13 100644 --- a/finvizfinance/screener/ticker.py +++ b/finvizfinance/screener/ticker.py @@ -8,14 +8,20 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Ticker(Overview): """Financial inherit from overview module. Getting information from the finviz screener ticker page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=411{signal}{filter}&ft=4{ticker}" ) @@ -23,7 +29,7 @@ def __init__(self): Overview._load_setting(self) def _screener_helper(self, i, page, soup, tickers, limit): - table = soup.findAll("table")[19] + table = soup.findAll("table")[self._screener_table_index] page_tickers = table.findAll("span") if i == page - 1: page_tickers = page_tickers[: ((limit - 1) % 1000 + 1)] diff --git a/finvizfinance/screener/valuation.py b/finvizfinance/screener/valuation.py index 0709f45..f41147e 100644 --- a/finvizfinance/screener/valuation.py +++ b/finvizfinance/screener/valuation.py @@ -7,14 +7,21 @@ .. moduleauthor:: Tianning Li """ +SCREENER_TABLE_INDEX = 21 + class Valuation(Overview): """Valuation inherit from overview module. Getting information from the finviz screener valuation page. + + Args: + screener_table_index(int): table index of the stock screener. change only if change on finviz side. + """ - def __init__(self): + def __init__(self, screener_table_index=SCREENER_TABLE_INDEX): """initiate module""" + self._screener_table_index = screener_table_index self.BASE_URL = ( "https://finviz.com/screener.ashx?v=121{signal}{filter}&ft=4{ticker}" ) diff --git a/finvizfinance/util.py b/finvizfinance/util.py index 820b879..8d837e9 100644 --- a/finvizfinance/util.py +++ b/finvizfinance/util.py @@ -126,7 +126,7 @@ def image_scrap(url, ticker, out_dir): raise Exception(err) -def scrap_function(url): +def scrap_function(url, table_index): """Scrap forex, crypto information. Args: @@ -135,7 +135,7 @@ def scrap_function(url): df(pandas.DataFrame): performance table """ soup = web_scrap(url) - table = soup.findAll("table")[3] + table = soup.findAll("table")[table_index] rows = table.findAll("tr") table_header = [i.text.strip() for i in rows[0].findAll("td")][1:] df = pd.DataFrame([], columns=table_header) diff --git a/release.md b/release.md index 09e5a5d..9d8e3fc 100644 --- a/release.md +++ b/release.md @@ -1,8 +1,9 @@ | Date | Version | Comment | | ------------- | ------------- | ------------- | -| 2022/05/02 | 0.12.2 | Fix screener error due to carelessness. | -| 2022/05/02 | 0.12.1 | Update changes in stock insider due to finviz's change. | -| 2022/05/02 | 0.12.0 | Update changes in stock screener. Issue: https://github.com/lit26/finvizfinance/issues/41| +| 2022/03/28 | 0.13.0 | Update changes in multiple module due to finviz's change. Issue: https://github.com/lit26/finvizfinance/issues/45 , https://github.com/lit26/finvizfinance/issues/46 | +| 2022/03/02 | 0.12.2 | Fix screener error due to carelessness. | +| 2022/03/02 | 0.12.1 | Update changes in stock insider due to finviz's change. | +| 2022/03/02 | 0.12.0 | Update changes in stock screener. Issue: https://github.com/lit26/finvizfinance/issues/41| | 2021/12/30 | 0.11.1 | Update changes in stock fundamental. Issue: https://github.com/lit26/finvizfinance/issues/38. PR: https://github.com/lit26/finvizfinance/pull/37 | | 2021/12/11 | 0.11 | Reformat the code to follow PEP 8 style guide. | | 2021/10/14 | 0.10.1 | Add pagination to the screener. https://github.com/lit26/finvizfinance/issues/29 | diff --git a/setup.py b/setup.py index 808d900..675ebe0 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ HERE = pathlib.Path(__file__).parent -VERSION = '0.12.2' +VERSION = '0.13.0' PACKAGE_NAME = 'finvizfinance' AUTHOR = 'Tianning Li' AUTHOR_EMAIL = 'ltianningli@gmail.com' diff --git a/tsla.jpg b/tsla.jpg index d68b0d0..a488cff 100644 Binary files a/tsla.jpg and b/tsla.jpg differ