diff --git a/bot/stockBot.py b/bot/stockBot.py index 481d543..346d01b 100644 --- a/bot/stockBot.py +++ b/bot/stockBot.py @@ -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 diff --git a/bot/tickerInfo.py b/bot/tickerInfo.py index be36a50..c7a97a8 100644 --- a/bot/tickerInfo.py +++ b/bot/tickerInfo.py @@ -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