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:
74
functions.py
74
functions.py
@@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user