From ee89528eb0cc5ba6b3d41b6f5daffc8e7e01b33c Mon Sep 17 00:00:00 2001 From: Tianning Li Date: Thu, 14 Oct 2021 18:16:48 -0700 Subject: [PATCH] update version 0.10 --- docs/conf.py | 2 +- finvizfinance/__init__.py | 2 +- finvizfinance/group/custom.py | 98 ++++++++++++++++++++++++++++++++ finvizfinance/screener/custom.py | 4 +- release.md | 1 + setup.py | 2 +- 6 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 finvizfinance/group/custom.py diff --git a/docs/conf.py b/docs/conf.py index 21c649c..0aa610f 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.9.10' +release = '0.10' # -- General configuration --------------------------------------------------- diff --git a/finvizfinance/__init__.py b/finvizfinance/__init__.py index 596a5d6..5dc1196 100644 --- a/finvizfinance/__init__.py +++ b/finvizfinance/__init__.py @@ -5,5 +5,5 @@ .. moduleauthor:: Tianning Li """ -__version__ = "0.9.9" +__version__ = "0.10" __author__ = "Tianning Li" diff --git a/finvizfinance/group/custom.py b/finvizfinance/group/custom.py new file mode 100644 index 0000000..4a58662 --- /dev/null +++ b/finvizfinance/group/custom.py @@ -0,0 +1,98 @@ +import pandas as pd +from finvizfinance.util import webScrap, numberCovert +from finvizfinance.group.overview import Overview +""" +.. module:: group.custom + :synopsis: group custom table. + +.. moduleauthor:: Tianning Li +""" + + +COLUMNS = { + 0: 'No.', + 1: 'Name', + 2: 'Market Cap.', + 3: 'P/E', + 4: 'Forward P/E', + 5: 'PEG', + 6: 'P/S', + 7: 'P/B', + 8: 'P/Cash', + 9: 'P/Free Cash Flow', + 10: 'Dividend Yield', + 11: 'EPS growth past 5 years', + 12: 'EPS growth next 5 years', + 13: 'Sales growth past 5 years', + 14: 'Shares Float', + 15: 'Performance (Week)', + 16: 'Performance (Month)', + 17: 'Performance (Quarter)', + 18: 'Performance (Half Year)', + 19: 'Performance (Year)', + 20: 'Performance (YearToDate)', + 21: 'Analyst Recom.', + 22: 'Average Volume', + 23: 'Relative Volume', + 24: 'Change', + 25: 'Volume', + 26: 'Number of Stocks' +} + + +class Custom(Overview): + """Custom inherit from overview module. + Getting information from the finviz group custom page. + """ + def __init__(self): + """initiate module + """ + self.BASE_URL = 'https://finviz.com/groups.ashx?{group}&v=152' + self.url = self.BASE_URL.format(group='g=sector') + Overview._loadSetting(self) + + def getColumns(self): + """Get information about the columns + + Returns: + columns(dict): return the index and column name. + """ + return COLUMNS + + def ScreenerView(self, group='Sector', order='Name', columns=[0, 1, 2, 3, 10, 22, 24, 25, 26]): + """Get screener table. + + Args: + group(str): choice of group option. + order(str): sort the table by the choice of order. + columns(list): columns of your choice. Default index: 0, 1, 2, 3, 10, 22, 24, 25, 26. + Returns: + df(pandas.DataFrame): group information table. + """ + if group not in self.group_dict: + raise ValueError() + if order not in self.order_dict: + raise ValueError() + self.url = self.BASE_URL.format(group=self.group_dict[group])+'&'+self.order_dict[order] + columns = [str(i) for i in columns] + self.url += '&c=' + ','.join(columns) + + soup = webScrap(self.url) + table = soup.findAll('table')[6] + rows = table.findAll('tr') + table_header = [i.text for i in rows[0].findAll('td')][1:] + df = pd.DataFrame([], columns=table_header) + rows = rows[1:] + num_col_index = [i for i in range(2, len(table_header))] + for row in rows: + cols = row.findAll('td')[1:] + info_dict = {} + for i, col in enumerate(cols): + # check if the col is number + if i not in num_col_index: + info_dict[table_header[i]] = col.text + else: + info_dict[table_header[i]] = numberCovert(col.text) + + df = df.append(info_dict, ignore_index=True) + return df \ No newline at end of file diff --git a/finvizfinance/screener/custom.py b/finvizfinance/screener/custom.py index 08ef6b8..f39e322 100644 --- a/finvizfinance/screener/custom.py +++ b/finvizfinance/screener/custom.py @@ -8,7 +8,7 @@ .. moduleauthor:: Tianning Li """ -columns = { +COLUMNS = { 0: 'No.', 1: 'Ticker', 2: 'Company', @@ -100,7 +100,7 @@ def getColumns(self): Returns: columns(dict): return the index and column name. """ - return columns + return COLUMNS def _screener_helper(self, i, page, rows, df, num_col_index, table_header, limit): """Get screener table helper function. diff --git a/release.md b/release.md index f90b796..ed73ae7 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,6 @@ | Date | Version | Comment | | ------------- | ------------- | ------------- | +| 2021/10/14 | 0.10 | Add group group | | 2021/07/03 | 0.9.10 | Add sec doc link https://github.com/lit26/finvizfinance/issues/26 | | 2021/07/03 | 0.9.9 | Add calendar module. Fixing import package order. Add package version https://github.com/lit26/finvizfinance/issues/25.| | 2021/05/08 | 0.9.8 | Adding data type in Quote file.| diff --git a/setup.py b/setup.py index ee622a0..40389cf 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ HERE = pathlib.Path(__file__).parent -VERSION = '0.9.10' +VERSION = '0.10' PACKAGE_NAME = 'finvizfinance' AUTHOR = 'Tianning Li' AUTHOR_EMAIL = 'ltianningli@gmail.com'