Skip to content

Commit

Permalink
Added get_stock and get_insider
Browse files Browse the repository at this point in the history
  • Loading branch information
mariostoev committed Jan 20, 2019
1 parent adab450 commit 67e316d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion finviz/__init__.py
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
40 changes: 40 additions & 0 deletions finviz/main_func.py
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

0 comments on commit 67e316d

Please sign in to comment.