Skip to content

Commit

Permalink
Methods for individual stock symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
mariostoev committed Jan 21, 2019
1 parent 67e316d commit a578326
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ parts/
sdist/
var/
wheels/
finviz/test.py
finviz/portfolio.csv
*.egg-info/
.installed.cfg
*.egg
Expand Down
3 changes: 2 additions & 1 deletion finviz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from finviz.screener import Screener
from finviz.portfolio import Portfolio
from finviz.main_func import get_stock
from finviz.main_func import get_insider
from finviz.main_func import get_insider
from finviz.main_func import get_news
20 changes: 18 additions & 2 deletions finviz/main_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def get_stock(ticker):

def get_insider(ticker):
"""
Returns a list of sets containing all recent insider transactions.
Returns a list of dictionaries containing all recent insider transactions.
:param ticker: stock symbol
:return:
:return: list
"""

page_parsed, _ = http_request_get(url=STOCK_URL, payload={'t': ticker}, parse=True)
Expand All @@ -38,3 +38,19 @@ def get_insider(ticker):
data = [dict(zip(headers, row.xpath('td//text()'))) for row in table[1:]]

return data


def get_news(ticker):
"""
Returns a list of sets containing news headlines and urls
:param ticker: stock symbol
:return: list
"""

page_parsed, _ = http_request_get(url=STOCK_URL, payload={'t': ticker}, parse=True)
all_news = page_parsed.cssselect('a[class="tab-link-news"]')
headlines = [row.xpath('text()')[0] for row in all_news]
urls = [row.get('href') for row in all_news]

return list(zip(headlines, urls))

0 comments on commit a578326

Please sign in to comment.