Всем привет, помогите упростить код пайтон. Код написан только для ПН и ВТ и для одной группы. Если продолжить таким методом писать, то он получится громадным
# Проверка группы (Reply)
def connect(message: types.Message):
cursor.execute('SELECT grup FROM Users WHERE id = ?', (message.from_user.id,))
result = cursor.fetchone()
if result is not None:
print('not none')
return result
# Проверка группы (Inline)
def connect1(call: CallbackQuery):
cursor.execute('SELECT grup FROM Users WHERE id = ?', (call.from_user.id,))
result = cursor.fetchone()
if result is not None:
print('not none')
return result
@dp.message_handler(text='ПН')
async def pn(message: types.Message):
result = connect(message=message)
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__PN_n'")
row = cursor.fetchone()
await message.answer(row[0], reply_markup=il_1)
@dp.message_handler(text='ВТ')
async def send_text(message: types.Message):
result = connect(message=message)
if result is None:
print('none')
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__VT_n'")
row = cursor.fetchone()
await message.answer(row[0], reply_markup=il_3)
@dp.callback_query_handler(text='PN_p')
async def answer(call: CallbackQuery):
result = connect1(call)
if result is None:
print('none')
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__PN_p'")
row = cursor.fetchone()
await call.message.answer(row[0], reply_markup=il_2)
@dp.callback_query_handler(text='PN_n')
async def answer(call: CallbackQuery):
result = connect1(call)
if result is None:
print('none')
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__PN_n'")
row = cursor.fetchone()
await call.message.answer(row[0], reply_markup=il_1)
@dp.callback_query_handler(text='VT_p')
async def answer(call: CallbackQuery):
result = connect1(call)
if result is None:
print('none')
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__VT_p'")
row = cursor.fetchone()
await call.message.answer(row[0], reply_markup=il_4)
@dp.callback_query_handler(text='VT_n')
async def answer(call: CallbackQuery):
result = connect1(call)
if result is None:
print('none')
for row in result:
if row == 'СВ-31':
cursor.execute("SELECT `raspisanie` FROM `Schedule` WHERE `grup` = 'SV_31__VT_n'")
row = cursor.fetchone()
await call.message.answer(row[0], reply_markup=il_3)