mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-07-25 23:51:32 +00:00
renamed ticker to symbol everywhere
This commit is contained in:
40
bot.py
40
bot.py
@@ -7,7 +7,7 @@ from functions import *
|
||||
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
|
||||
|
||||
TELEGRAM_TOKEN = os.environ["TELEGRAM"]
|
||||
TICKER_REGEX = "[$]([a-zA-Z]{1,4})"
|
||||
symbol_REGEX = "[$]([a-zA-Z]{1,4})"
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(
|
||||
@@ -31,19 +31,19 @@ def help(bot, update):
|
||||
update.message.reply_text(text=message, parse_mode=telegram.ParseMode.MARKDOWN)
|
||||
|
||||
|
||||
def tickerDetect(bot, update):
|
||||
def symbolDetect(bot, update):
|
||||
"""
|
||||
Runs on any message that doesn't have a command and searches for tickers, then returns the prices of any tickers found.
|
||||
Runs on any message that doesn't have a command and searches for symbols, then returns the prices of any symbols found.
|
||||
"""
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
tickers = getTickers(message)
|
||||
symbols = getSymbols(message)
|
||||
|
||||
if tickers:
|
||||
if symbols:
|
||||
# Let user know bot is working
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for symbol, reply in tickerDataReply(tickers).items():
|
||||
for symbol, reply in symbolDataReply(symbols).items():
|
||||
|
||||
update.message.reply_text(
|
||||
text=reply, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
@@ -52,16 +52,16 @@ def tickerDetect(bot, update):
|
||||
|
||||
def dividend(bot, update):
|
||||
"""
|
||||
waits for /dividend or /div command and then finds dividend info on that ticker.
|
||||
waits for /dividend or /div command and then finds dividend info on that symbol.
|
||||
"""
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
tickers = getTickers(message)
|
||||
symbols = getSymbols(message)
|
||||
|
||||
if tickers:
|
||||
if symbols:
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for symbol, reply in tickerDividend(tickers).items():
|
||||
for symbol, reply in symbolDividend(symbols).items():
|
||||
|
||||
update.message.reply_text(
|
||||
text=reply, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
@@ -70,16 +70,16 @@ def dividend(bot, update):
|
||||
|
||||
def news(bot, update):
|
||||
"""
|
||||
waits for /news command and then finds news info on that ticker.
|
||||
waits for /news command and then finds news info on that symbol.
|
||||
"""
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
tickers = getTickers(message)
|
||||
symbols = getSymbols(message)
|
||||
|
||||
if tickers:
|
||||
if symbols:
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for symbol, reply in tickerNews(tickers).items():
|
||||
for symbol, reply in symbolNews(symbols).items():
|
||||
|
||||
update.message.reply_text(
|
||||
text=reply, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
@@ -88,16 +88,16 @@ def news(bot, update):
|
||||
|
||||
def info(bot, update):
|
||||
"""
|
||||
waits for /info command and then finds info on that ticker.
|
||||
waits for /info command and then finds info on that symbol.
|
||||
"""
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
tickers = getTickers(message)
|
||||
symbols = getSymbols(message)
|
||||
|
||||
if tickers:
|
||||
if symbols:
|
||||
bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for symbol, reply in tickerInfo(tickers).items():
|
||||
for symbol, reply in symbolInfo(symbols).items():
|
||||
|
||||
update.message.reply_text(
|
||||
text=reply, parse_mode=telegram.ParseMode.MARKDOWN
|
||||
@@ -126,7 +126,7 @@ def main():
|
||||
dp.add_handler(CommandHandler("info", info))
|
||||
|
||||
# on noncommand i.e message - echo the message on Telegram
|
||||
dp.add_handler(MessageHandler(Filters.text, tickerDetect))
|
||||
dp.add_handler(MessageHandler(Filters.text, symbolDetect))
|
||||
|
||||
# log all errors
|
||||
dp.add_error_handler(error)
|
||||
@@ -141,4 +141,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
Reference in New Issue
Block a user