I’m trying to build a bot that fetches stock data from financial websites and sends it to users when they message the bot. However, I keep getting errors about the Updater class not being found.
Here’s my current code:
import requests
from telegram.ext import Application, CommandHandler
from bs4 import BeautifulSoup
def fetch_stock_data(ticker):
endpoint = f"https://finance.yahoo.com/quote/{ticker}"
response = requests.get(endpoint)
parser = BeautifulSoup(response.content, "html.parser")
stock_value = parser.find("span", {"data-reactid": "14"}).get_text()
return stock_value
def send_stocks(update, context):
tickers = ["^IXIC", "^RUT"]
values = [fetch_stock_data(ticker) for ticker in tickers]
reply = "NASDAQ: " + values[0] + "\n" + "Russell: " + values[1]
context.bot.send_message(chat_id=update.message.chat_id, text=reply)
my_token = "YOUR_BOT_TOKEN"
app = Application.builder().token(my_token).build()
stock_cmd = CommandHandler("stocks", send_stocks)
app.add_handler(stock_cmd)
app.run_polling()
The error I receive is:
AttributeError: module 'telegram' has no attribute 'Updater'
I’ve tried reinstalling the telegram library, but I’m still having issues. What’s the proper way to handle this in newer versions of the library?