Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no global STOCK_PAGE #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions finviz/main_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
STOCK_URL = "https://finviz.com/quote.ashx"
NEWS_URL = "https://finviz.com/news.ashx"
CRYPTO_URL = "https://finviz.com/crypto_performance.ashx"
STOCK_PAGE = {}


def get_page(ticker):
global STOCK_PAGE
STOCK_PAGE, _ = http_request_get(
url=STOCK_URL, payload={"t": ticker}, parse=True
)

if ticker not in STOCK_PAGE:
STOCK_PAGE[ticker], _ = http_request_get(
url=STOCK_URL, payload={"t": ticker}, parse=True
)
return STOCK_PAGE


def get_stock(ticker):
Expand All @@ -29,8 +27,7 @@ def get_stock(ticker):
:return dict
"""

get_page(ticker)
page_parsed = STOCK_PAGE[ticker]
page_parsed = get_page(ticker)

title = page_parsed.cssselect('table[class="fullview-title"]')[0]
keys = ["Company", "Sector", "Industry", "Country"]
Expand Down Expand Up @@ -69,8 +66,7 @@ def get_insider(ticker):
:return: list
"""

get_page(ticker)
page_parsed = STOCK_PAGE[ticker]
page_parsed = get_page(ticker)
outer_table = page_parsed.cssselect('table[class="body-table"]')

if len(outer_table) == 0:
Expand All @@ -95,8 +91,7 @@ def get_news(ticker):
:return: list
"""

get_page(ticker)
page_parsed = STOCK_PAGE[ticker]
page_parsed = get_page(ticker)
news_table = page_parsed.cssselect('table[id="news-table"]')

if len(news_table) == 0:
Expand Down Expand Up @@ -173,8 +168,7 @@ def get_analyst_price_targets(ticker, last_ratings=5):
analyst_price_targets = []

try:
get_page(ticker)
page_parsed = STOCK_PAGE[ticker]
page_parsed = get_page(ticker)
table = page_parsed.cssselect('table[class="fullview-ratings-outer"]')[0]

for row in table:
Expand Down