Skip to content

Commit

Permalink
Merge pull request #47 from lit26/fix
Browse files Browse the repository at this point in the history
Update changes in multiple module due to finviz change
  • Loading branch information
lit26 authored Mar 28, 2022
2 parents 243937b + 502548b commit e443456
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion finvizfinance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""

__version__ = "0.12.2"
__version__ = "0.13.0"
__author__ = "Tianning Li"
10 changes: 7 additions & 3 deletions finvizfinance/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""

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.
Expand All @@ -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):
Expand Down
11 changes: 8 additions & 3 deletions finvizfinance/forex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""

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.
Expand All @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions finvizfinance/group/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions finvizfinance/group/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion finvizfinance/group/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""

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)
7 changes: 6 additions & 1 deletion finvizfinance/group/valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""
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)
7 changes: 5 additions & 2 deletions finvizfinance/insider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

INSIDER_URL = "https://finviz.com/insidertrading.ashx"
INSIDER_TABLE_INDEX = 6


class Insider:
Expand All @@ -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":
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions finvizfinance/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
22 changes: 17 additions & 5 deletions finvizfinance/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"EPS nest Y",
"Insider ",
]
TICKER_FUNDAMENT_TABLE_INDEX = 6


class Quote:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 10 additions & 3 deletions finvizfinance/screener/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion finvizfinance/screener/financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
.. moduleauthor:: Tianning Li <[email protected]>
"""

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}"
)
Expand Down
Loading

0 comments on commit e443456

Please sign in to comment.