I'm writing the telegram bot, currently I'm doing the buttons which handles the text, if you press the button it's supposed to open the recipe from the dictionary with the name which is the same with the button name. I have over hundreds of recipes, so I don't want to do every button by myself, so I wrote a function which does it, but for some reason it doesn't work properly. It always backs the last value from the dictionary. What should I change?
for inx, recipe_name in enumerate(breakfast_titles_rus):
key = f'{inx + 1}. {recipe_name}'
recipe2idx[key] = inx
for key, inx in recipe2idx.items():
@dp.message_handler(text=[key])
async def breakfest_fist_choice(message: types.message):
print(key)
name=key.split('.')
name.pop(0)
clear=f'{name[0].lstrip()}'
print(clear)
if ('item_name', clear) in breakfast_dict.items():
for k, v in list(breakfast_dict.items())[:inx]:
breakfast_card_rus=f"\nНазвание: {v['item_name']}\nВремя: " f"{v['item_times']}\nКоличетсво лайков: " f"{v['item_rating']}\nКоличество ингредиентов: " f"{v['items_total_amount_ingridients']}\nКоличество каллорий: " f"{v['item_kcal']}\nКоличество белков: " f"{v['item_belki']}\nКоличество жиров: " f"{v['item_zhiri']}\nКоличество углеводов: " f"{v['item_uglevodi']}\n\nНеобходимые ингредиенты: "f"{v['item_ingridients']}\n\nРецепет: "f"{v['item_recipe']}"f"{v['item_photo']}"
back_to_menu=KeyboardButton("Назад к началу")
mark_up=ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True).add(back_to_menu)
await bot.send_message(message.from_user.id, text=breakfast_card_rus, reply_markup=mark_up)
I tried to debug it by myself, and it didn't work.