Exemplo n.º 1
0
async def remove_all_products_yes(call: CallbackQuery):
    """Обработка инлайн кнопки на подтверждение удаление товара"""
    try:
        init_db()
        remove_all_products_db()
        await call.message.answer('🎉 Все товары были удалены!')
        logger.info('All items have been removed')
    except Exception as e:
        logger.error('Error while deleting an item' + str(e))
Exemplo n.º 2
0
def get_file_section(lines,
                     start_line_num=0,
                     skip_before=None,
                     skip_after=None,
                     notstartswith=None):
    """Return file section from a file content list

    :param list lines: a list of file contents, each element is a line from the file
    :param int start_line_num: read from this line number and below
    :param str skip_before: skip content before this string
    :param str skip_after: skip content after this string
    :param str notstartswith: skip line which starts with this string
    """
    retval = lines[start_line_num:]
    if retval and skip_before:
        try:
            retval = retval[retval.index(skip_before) + 1:]
        except ValueError as e:
            logger.error(e)
            logger.error(skip_before + ' is not found')
    if retval and skip_after:
        try:
            retval = retval[:retval.index(skip_after) - 1]
        except ValueError as e:
            logger.error(e)
            logger.error(skip_after + ' is not found')

    # this section should be after skip operation above
    # in case the skip string is also start with "notstartswith"
    retval = [item for item in retval if not item.startswith(notstartswith)]

    return retval