mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 15:17:28 +00:00
added /info command
This commit is contained in:
parent
fd1baad811
commit
211fd0e2a9
21
bot.py
21
bot.py
@ -86,6 +86,24 @@ def news(bot, update):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def info(bot, update):
|
||||||
|
"""
|
||||||
|
waits for /info command and then finds info on that ticker.
|
||||||
|
"""
|
||||||
|
message = update.message.text
|
||||||
|
chat_id = update.message.chat_id
|
||||||
|
tickers = getTickers(message)
|
||||||
|
|
||||||
|
if tickers:
|
||||||
|
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||||
|
|
||||||
|
for symbol, reply in tickerInfo(tickers).items():
|
||||||
|
|
||||||
|
update.message.reply_text(
|
||||||
|
text=reply, parse_mode=telegram.ParseMode.MARKDOWN
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def error(bot, update, error):
|
def error(bot, update, error):
|
||||||
"""Log Errors caused by Updates."""
|
"""Log Errors caused by Updates."""
|
||||||
logger.warning('Update "%s" caused error "%s"', update, error)
|
logger.warning('Update "%s" caused error "%s"', update, error)
|
||||||
@ -105,6 +123,7 @@ def main():
|
|||||||
dp.add_handler(CommandHandler("dividend", dividend))
|
dp.add_handler(CommandHandler("dividend", dividend))
|
||||||
dp.add_handler(CommandHandler("div", dividend))
|
dp.add_handler(CommandHandler("div", dividend))
|
||||||
dp.add_handler(CommandHandler("news", news))
|
dp.add_handler(CommandHandler("news", news))
|
||||||
|
dp.add_handler(CommandHandler("info", info))
|
||||||
|
|
||||||
# on noncommand i.e message - echo the message on Telegram
|
# on noncommand i.e message - echo the message on Telegram
|
||||||
dp.add_handler(MessageHandler(Filters.text, tickerDetect))
|
dp.add_handler(MessageHandler(Filters.text, tickerDetect))
|
||||||
@ -122,4 +141,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
23
functions.py
23
functions.py
@ -98,3 +98,26 @@ def tickerNews(tickers: list):
|
|||||||
] = f"No news found for: {ticker}\nEither today is boring or the ticker does not exist."
|
] = f"No news found for: {ticker}\nEither today is boring or the ticker does not exist."
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
def tickerInfo(tickers: list):
|
||||||
|
messages = {}
|
||||||
|
|
||||||
|
for ticker in tickers:
|
||||||
|
IEXurl = (
|
||||||
|
f"https://cloud.iexapis.com/stable/stock/{ticker}/company?token={IEX_TOKEN}"
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(IEXurl) as url:
|
||||||
|
data = json.loads(url.read().decode())
|
||||||
|
if data:
|
||||||
|
messages[
|
||||||
|
ticker
|
||||||
|
] = f"Company Name: [{data['companyName']}]({data['website']})\nIndustry: {data['industry']}\nSector: {data['sector']}\nCEO: {data['CEO']}\nDescription: {data['description']}\n"
|
||||||
|
|
||||||
|
else:
|
||||||
|
messages[
|
||||||
|
ticker
|
||||||
|
] = f"No information found for: {ticker}\nEither today is boring or the ticker does not exist."
|
||||||
|
|
||||||
|
return messages
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user