Пример #1
0
    def products_menu_inline(self, ProductCategory):
        keyboard = telebot.types.InlineKeyboardMarkup()
        btn = []

        f = open('text.txt', 'r+')
        products = []
        for line in f.readlines():
            try:
                line = line.split('|')
                if line[1] not in products and line[0] == ProductCategory:
                    products.append(line[1])
            except:
                pass
        f.close()

        for i in products:
            btn.append(
                createBtn(text=str(i),
                          callback_data='productcount_' + ProductCategory +
                          '_' + str(i)))

        if len(btn) % 2 == 0:
            for i in range(0, len(btn), 2):
                keyboard.row(btn[i], btn[i + 1])
        else:
            for i in range(0, len(btn) - 1, 2):
                keyboard.row(btn[i], btn[i + 1])
            keyboard.row(btn[len(btn) - 1])
        keyboard.row(
            createBtn(text=lang.us.escape_btn, callback_data='categorylist'))
        return keyboard
Пример #2
0
    def category_menu_inline(self):
        keyboard = telebot.types.InlineKeyboardMarkup()
        btn = []

        f = open('text.txt', 'r+')
        categories = []
        for line in f.readlines():
            if line[0] != ' ':
                temp = line.split('|')
                if temp[0] not in categories:
                    categories.append(temp[0])
            else:
                pass
        categories = categories[:-1]
        f.close()

        for i in categories:
            btn.append(createBtn(text=i,
                                 callback_data='productlist_' + str(i)))
        if len(btn) % 2 == 0:
            for i in range(0, len(btn), 2):
                keyboard.row(btn[i], btn[i + 1])
        else:
            for i in range(0, len(btn) - 1, 2):
                keyboard.row(btn[i], btn[i + 1])
            keyboard.row(btn[len(btn) - 1])

        return keyboard