-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
.. moduleauthor:: Tianning Li <[email protected]> | ||
""" | ||
|
||
__version__ = "0.9.9" | ||
__version__ = "0.10" | ||
__author__ = "Tianning Li" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
""" | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
.. moduleauthor:: Tianning Li <[email protected]> | ||
""" | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
HERE = pathlib.Path(__file__).parent | ||
|
||
VERSION = '0.9.10' | ||
VERSION = '0.10' | ||
PACKAGE_NAME = 'finvizfinance' | ||
AUTHOR = 'Tianning Li' | ||
AUTHOR_EMAIL = '[email protected]' | ||
|