import logging from aiogram import types from load import dp from keyboards.inline.keyboard import cancel_button, menu from parser import get_about_replacements @dp.callback_query_handler(lambda c: c.data != "back" and not len(c.data.split("|")) == 2) async def callback_query(query: types.CallbackQuery): from_user = query.from_user data = get_about_replacements() group = query.data logging.info("Button: {btn}, User: {user_id} - {username}".format( user_id=str(from_user.id), username=str(from_user.username), btn=str(group) )) if group in data['data']: await query.message.edit_text( text="Группа: {group}\nЗамены: {replace}" .format( group=str(group), replace=data['data'][group] ), reply_markup=cancel_button ) else: await query.message.edit_text( text=( "Группа: {group} не найдена!\n" "Список обновится автоматически после нажатия кнопки ниже" ) .format( group=str(group), ), reply_markup=cancel_button ) #await query.answer() @dp.callback_query_handler(lambda c: c.data == "back") async def back_button(query: types.CallbackQuery): data = get_about_replacements() await query.message.edit_text( "{date}\n{teacher}\nВыберите свою группу" .format( date=data["date"], teacher=data["another_teacher"] ), reply_markup=menu(data["data"]) ) await query.answer()