mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
removed news since no longer supported by IEX
This commit is contained in:
parent
3113c17efb
commit
6b679963dd
25
bot.py
25
bot.py
@ -50,31 +50,6 @@ def tickerDetect(bot, update):
|
|||||||
update.message.reply_text(text=reply, parse_mode=telegram.ParseMode.MARKDOWN)
|
update.message.reply_text(text=reply, parse_mode=telegram.ParseMode.MARKDOWN)
|
||||||
|
|
||||||
|
|
||||||
def news(bot, update):
|
|
||||||
"""
|
|
||||||
/news
|
|
||||||
Returns a small snippet of general information, and any news articles that are found.
|
|
||||||
"""
|
|
||||||
message = update.message.text
|
|
||||||
chat_id = update.message.chat_id
|
|
||||||
|
|
||||||
# Let user know bot is working
|
|
||||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
|
||||||
|
|
||||||
tickers = getTickers(message)
|
|
||||||
|
|
||||||
news = tickerNews(tickers) if tickers else {}
|
|
||||||
|
|
||||||
for ticker in news:
|
|
||||||
|
|
||||||
reply = tickerNewsReply(news[ticker])
|
|
||||||
update.message.reply_text(text=reply, parse_mode=telegram.ParseMode.MARKDOWN)
|
|
||||||
|
|
||||||
# Keep track of which tickers had a return from tickerData()
|
|
||||||
if ticker.lower() in tickers:
|
|
||||||
tickers.remove(ticker.lower())
|
|
||||||
|
|
||||||
|
|
||||||
def dividend(bot, update):
|
def dividend(bot, update):
|
||||||
"""
|
"""
|
||||||
This Functions is incomplete.
|
This Functions is incomplete.
|
||||||
|
74
functions.py
74
functions.py
@ -45,80 +45,6 @@ def tickerDataReply(tickers: list):
|
|||||||
return tickerReplies
|
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
|
# Below Functions are incomplete
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user