forked from mariostoev/finviz
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
adab450
commit 67e316d
Showing
2 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from finviz.screener import Screener | ||
from finviz.screener import Screener | ||
from finviz.portfolio import Portfolio | ||
from finviz.main_func import get_stock | ||
from finviz.main_func import get_insider |
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,40 @@ | ||
from finviz.helper_functions.request_functions import http_request_get | ||
|
||
STOCK_URL = 'https://finviz.com/quote.ashx' | ||
|
||
|
||
def get_stock(ticker): | ||
""" | ||
Returns a dictionary containing stock data. | ||
:param ticker: stock symbol | ||
:type ticker: str | ||
:return dict | ||
""" | ||
|
||
data = {} | ||
page_parsed, _ = http_request_get(url=STOCK_URL, payload={'t': ticker}, parse=True) | ||
all_rows = [row.xpath('td//text()') for row in page_parsed.cssselect('tr[class="table-dark-row"]')] | ||
|
||
for row in all_rows: | ||
for column in range(0, 11): | ||
if column % 2 == 0: | ||
data[row[column]] = row[column + 1] | ||
|
||
return data | ||
|
||
|
||
def get_insider(ticker): | ||
""" | ||
Returns a list of sets containing all recent insider transactions. | ||
:param ticker: stock symbol | ||
:return: | ||
""" | ||
|
||
page_parsed, _ = http_request_get(url=STOCK_URL, payload={'t': ticker}, parse=True) | ||
table = page_parsed.cssselect('table[class="body-table"]')[0] | ||
headers = table[0].xpath('td//text()') | ||
data = [dict(zip(headers, row.xpath('td//text()'))) for row in table[1:]] | ||
|
||
return data |