'When doing a 2 query it does not search the database again

At the moment of executing the bot if it performs its operation correctly the first time, but later it does not consult the database again or continues to the cycle for "for idTelegram, Trunk in cur.fetchall() :"

Database connection


#Conexion a Base de Datos Para validacion
miConexion = mysql.connector.connect( host='localhost', user= 'root', passwd='', db='validacion' )
cur = miConexion.cursor()
cur = miConexion.cursor(buffered=True)
cur.execute( "SELECT idTelegram, Troncal FROM troncales" )

Telegram messages start and update functions

#Token de Telegram
updater = Updater(token="")
dispatcher = updater.dispatcher


ConsultarSaldoSw2 = "Consultar Saldo SW2"

def startCommand(update: Update, context: CallbackContext):
    buttons = [[KeyboardButton(ConsultarSaldoSw2)]]
    context.bot.send_message(chat_id=update.effective_chat.id, text="Bienvenido", reply_markup=ReplyKeyboardMarkup(buttons))

def messageHandler(update: Update, context: CallbackContext):
    
    bot = context.bot
    updateMsg = getattr(update, 'message', None)
    messageId = updateMsg.message_id
    chatId = update.message.chat_id
    userName = update.effective_user['username']
    text = update.message.text


    
    if ConsultarSaldoSw2 in update.message.text:
        context.bot.send_message(chat_id=update.effective_chat.id, text="Ingresa tu Nombre de Troncal")
        return text
    
    
    print (text)

At this point it is no longer executed when another request is sent through telegram

for idTelegram, Troncal in cur.fetchall() :
   print ("prueba")
   
   
   if userName in idTelegram:
       if text in Troncal:
         print ("Troncal Correcta "+ text)
         Saldo = client.getAccountInfo({ 'username':  (text)})
         SaldoESP1 = (f"{Saldo['balance']}")
         TroncalCompleta = (f"{Saldo['authname']}")
         Moneda = (f"{Saldo['base_currency']}")
         print (Saldo)

         integer = float(SaldoESP1)
         if integer < 0:
             Convertir = integer * -1
             print (Convertir)
             Convertir = str(Convertir)
             context.bot.send_message(chat_id=update.effective_chat.id, text= TroncalCompleta + " es "  + Convertir +" "+ Moneda )
             break
         elif integer > 0:
             Convertir = integer * -1
             print (Convertir)
             Convertir = str(Convertir)
             context.bot.send_message(chat_id=update.effective_chat.id, text= TroncalCompleta + " es "  + Convertir +" "+ Moneda )
             break
       else:
         print ("Troncal Incorrecto "+text)
         context.bot.send_message(chat_id=update.effective_chat.id, text="No estas permitido para ver esto" )
         break
   else:
       print ("Usuario Incorrecto "+userName)
       context.bot.send_message(chat_id=update.effective_chat.id, text="Usuario Incorrecto Validalo con soporte" )
       break
cur.reset()  
 dispatcher.add_handler(CommandHandler("start", startCommand))
 dispatcher.add_handler(MessageHandler(Filters.text, messageHandler))
 updater.start_polling()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source