1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-07-26 08:01:42 +00:00

removed news since no longer supported by IEX

This commit is contained in:
2019-05-27 09:19:42 -07:00
parent 3113c17efb
commit 6b679963dd
2 changed files with 0 additions and 99 deletions

View File

@@ -45,80 +45,6 @@ def tickerDataReply(tickers: list):
return tickerReplies
def tickerNews(tickers: list):
"""
Takes a list of ticker and returns a dictionary of dictionarys
with a list of tuples under news that contains (title, url)
example:
input list: ["aapl"]
returns:
{
"AAPL": {
"name": "Apple Inc.",
"price": 200.72,
"change": -0.01074,
"news": [
(
"April Dividend Income Report - Beating Records, Holding Steady",
"https://api.iextrading.com/1.0/stock/aapl/article/8556681822768653",
),
(
"Is Vanguard's VIG Better Than Its WisdomTree Counterpart?",
"https://api.iextrading.com/1.0/stock/aapl/article/7238581261167527",
),
],
}
}
"""
data = tickerData(tickers)
for ticker in tickers:
ticker = ticker.upper()
IEXNews = f"https://api.iextrading.com/1.0/stock/{ticker}/news/last/5"
with urllib.request.urlopen(IEXNews) as url:
newsData = json.loads(url.read().decode())
data[ticker]["news"] = []
for index, story in enumerate(newsData):
tup = (newsData[index]["headline"], newsData[index]["url"])
data[ticker]["news"].append(tup)
return data
def tickerNewsReply(ticker: dict):
"""
Takes a dictionary, likely produced from tickerNews(), and returns a markdown string with news information on the ticker.
example:
{
"name": "Apple Inc.",
"price": 200.72,
"change": -0.01074,
"news": [
(
"April Dividend Income Report - Beating Records, Holding Steady",
"https://api.iextrading.com/1.0/stock/aapl/article/8556681822768653",
),
(
"Is Vanguard's VIG Better Than Its WisdomTree Counterpart?",
"https://api.iextrading.com/1.0/stock/aapl/article/7238581261167527",
),
],
}
returns:
The current stock price of Apple Inc. is $**200.72**, the stock is currently **down -1.07%**
[April Dividend Income Report - Beating Records, Holding Steady](https://api.iextrading.com/1.0/stock/aapl/article/8556681822768653)
[Is Vanguard's VIG Better Than Its WisdomTree Counterpart?](https://api.iextrading.com/1.0/stock/aapl/article/7238581261167527)
"""
reply = tickerDataReply(ticker)
if len(ticker["news"]) == 0:
return reply + f"\n\tNo News was found for {ticker['name']}"
for title, url in ticker["news"]:
reply = reply + f"\n\t[{title}]({url})"
return reply
# Below Functions are incomplete