Python Forum
How to conditionally execute correctly?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to conditionally execute correctly?
#1
@bot.message_handler(commands=['start'])
def get_filial(message: types.Message):
    
    markup_inline_filial=types.InlineKeyboardMarkup()
    item_shop1=types.InlineKeyboardButton(text='Shop1', callback_data='shop1')
    item_shop2=types.InlineKeyboardButton(text='Shop2', callback_data='shop2')
    markup_inline_filial.add(item_shop1,item_shop2)

@bot.callback_query_handler(func=lambda call:call.data=='shop1')
def get_select_button_shop1(call: types.CallbackQuery):
    markup_inline_item=types.InlineKeyboardMarkup()
    markup_inline_item.add()
    bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop1(message):
    if message.text in ['1','2','3','4']:
        send_docs_shop1(message)
    else:
        send_query_shop1(message)

def send_docs_shop1(message):
    file_source=open(f"E:\shop1_{message.text}.csv")
    bot.send_document(message.chat.id, file_source) 
 
def send_query_shop1(message):
    bot.send_document(message.chat.id, "Hello from shop1")
 
@bot.callback_query_handler(func=lambda call:call.data=='shop2')
def get_select_button_shop2(call: types.CallbackQuery):
    markup_inline_item=types.InlineKeyboardMarkup()
    markup_inline_item.add()
    bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop2(message):
    if message.text =='o':
        send_docs_shop2(message)
    else:
        send_query_shop2(message)
    
def send_docs_shop2(message):
    file_source=open(f"E:\shop2_{message.text}.csv")
    bot.send_document(message.chat.id, file_source) 
 
def send_query_shop2(message):
    bot.send_document(message.chat.id, "Hello from shop2")
Reply
#2
There's code there and no real question. It would help if you told us what problem you're having, any errors, etc.
Reply
#3
Sorry, I need that when "Shop1" is selected, the code for "shop1" is executed, and when "Shop2" is selected, the code for "shop2" is executed.

Currently both "Shop1" and "Shop2" execute "Shop1".
Reply
#4
So how have you debugged the program to work out why it isn't working correctly?
Reply
#5
(Nov-12-2022, 08:15 AM)lolita7777 Wrote: Sorry, I need that when "Shop1" is selected, the code for "shop1" is executed, and when "Shop2" is selected, the code for "shop2" is executed.

Currently both "Shop1" and "Shop2" execute "Shop1".

sorry, beginner coder, so I don't know a lot of things yet
Reply
#6
help me please
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to conditionally specify markers in matplotlib graph Mark17 3 3,269 Mar-03-2022, 07:42 PM
Last Post: Mark17
  Conditionally lazy load modules amb85 1 2,117 Dec-10-2019, 07:24 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020