1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 15:17:28 +00:00

Ticker news now uses IEX news api #8 #3

This commit is contained in:
Anson 2019-02-12 19:58:44 -07:00
parent df7d69526e
commit 7485285426
2 changed files with 17 additions and 14 deletions

View File

@ -84,9 +84,11 @@ def news(bot, update):
message + ", the stock hasn't shown any movement today." message + ", the stock hasn't shown any movement today."
) )
news = tickerInfo.stockNewsList(ticker) news = tickerInfo.stockNews(ticker)
for source in news: for i in range(3):
message = message + "\n[" + source + "](" + news[source] + ")" message = "{}\n[{}]({})".format(
message, news["title"][i], news["link"][i]
)
update.message.reply_text( update.message.reply_text(
text=message, parse_mode=telegram.ParseMode.MARKDOWN text=message, parse_mode=telegram.ParseMode.MARKDOWN

View File

@ -1,5 +1,6 @@
import urllib.request import urllib.request
import json import json
import feedparser
def tickerQuote(tickers): def tickerQuote(tickers):
@ -32,19 +33,19 @@ def tickerQuote(tickers):
return stockData return stockData
def stockNewsList(ticker): def stockNews(ticker):
"""Makes a bunch of strings that are links to news websites for an input ticker""" """Makes a bunch of strings that are links to news websites for an input ticker"""
print("Gather News on " + ticker) print("Gather News on " + ticker)
news = {
"Bravos": "https://bravos.co/" + ticker, newsLink = "https://api.iextrading.com/1.0/stock/{}/news/last/5".format(ticker)
"Seeking Alpha": "https://seekingalpha.com/symbol/" + ticker,
"MSN Money": "https://www.msn.com/en-us/money/stockdetails?symbol=" + ticker, with urllib.request.urlopen(newsLink) as url:
"Yahoo Finance": "https://finance.yahoo.com/quote/" + ticker, data = json.loads(url.read().decode())
"Wall Street Journal": "https://quotes.wsj.com/" + ticker,
"The Street": "https://www.thestreet.com/quote/" + ticker + ".html", news = {"link": [], "title": []}
"Zacks": "https://www.zacks.com/stock/quote/" + ticker, for i in range(3):
} news["link"].append(data[i]["url"])
print("News gathered.") news["title"].append(data[i]["headline"])
return news return news