Python Forum
How to conditionally execute correctly? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to conditionally execute correctly? (/thread-38687.html)



How to conditionally execute correctly? - lolita7777 - Nov-12-2022

@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")



RE: How to conditionally execute correctly? - ndc85430 - Nov-12-2022

There's code there and no real question. It would help if you told us what problem you're having, any errors, etc.


RE: How to conditionally execute correctly? - lolita7777 - Nov-12-2022

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".


RE: How to conditionally execute correctly? - ndc85430 - Nov-12-2022

So how have you debugged the program to work out why it isn't working correctly?


RE: How to conditionally execute correctly? - lolita7777 - Nov-12-2022

(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


RE: How to conditionally execute correctly? - lolita7777 - Nov-16-2022

help me please