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."
)
news = tickerInfo.stockNewsList(ticker)
for source in news:
message = message + "\n[" + source + "](" + news[source] + ")"
news = tickerInfo.stockNews(ticker)
for i in range(3):
message = "{}\n[{}]({})".format(
message, news["title"][i], news["link"][i]
)
update.message.reply_text(
text=message, parse_mode=telegram.ParseMode.MARKDOWN

View File

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