Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

telegram bot carousel

def display_cart(self): # self это message
        try:
            global cart
            global counter
            counter = 0

            connection = db.create_connection(
                "merch_telegram_bot_db", "postgres", "password",
                "127.0.0.1",
                "5432"
            )
            query = q.interface_query[
                        'display_product_cart'] + str(self.from_user.id)
            cart = db.execution_of_requests(connection, query)
            connection.close()
            cart_keyboard = key.cart_keyboard()
            bot.send_message(self.chat.id, "Корзина:
")
            bot.send_message(self.chat.id, f"{cart[0][0]}
"
                                           f"{cart[0][1]}
"
                                           f"<a href='{cart[0][2]}'>&#8203"
                                           f";</a>",
                             parse_mode="HTML",
                             reply_markup=cart_keyboard)

        except Exception as e:
            print('Фатальная ошибка!' + f'
{str(e)}')
            return

    def callback_data_handler(self): # self это call (ответ inline кнопок)
        try:
            connection = db.create_connection(
                "merch_telegram_bot_db", "postgres", "password", "127.0.0.1",
                "5432"
            )
            id_element = extract_id(self.data)
            if id_element[0] == 'cat':
                query = q.interface_query['product'] + id_element[1]
                product = db.execution_of_requests(connection, query)
                bot.edit_message_text(chat_id=self.message.chat.id,
                                      message_id=self.message.message_id,
                                      text=f'{product[0][0]}')
                for i in product:
                    show_product_keyboard = key.show_product(i)
                    bot.send_photo(self.from_user.id, i[5],
                                   caption=f'
{i[2]}
{i[3]}',
                                   reply_markup=show_product_keyboard)
                bot.answer_callback_query(self.id, show_alert=False)
            elif id_element[0] == 'prod':
                query = q.interface_query['cart_id_info'] + 
                        str(self.from_user.id)
                cart_id = db.execution_of_requests(connection, query)
                query = q.interface_query['add_product_cart']
                data = (cart_id[0][0], id_element[1])
                db.execution_of_requests(connection, query, data)
                InterfaceInteraction.alert(self, "Товар добавлен в корзину")
            elif id_element[0] == 'delete':
                print("Ok_delete")
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'remove':
                print("Ok_remove")
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'add':
                print("Ok_add")
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'previous':
                print(self)
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'next':
                print(cart)
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'order':
                print("Ok_order")
                InterfaceInteraction.alert(self)
            elif id_element[0] == 'continue':
                print("Ok_continue")
                InterfaceInteraction.alert(self)
            else:
                InterfaceInteraction.alert(self)
            connection.close()
        except Exception as e:
            print('Фатальная ошибка!' + f'
{str(e)}')
            return
Comment

PREVIOUS NEXT
Code Example
Python :: deactivate pandas warning copy 
Python :: django.core.exceptions.ImproperlyConfigured: Field name is not valid for model 
Python :: new line eval python 
Python :: names of all methods in class introspect pythonm 
Python :: python list of paths 
Python :: Class 10: Conditional Statements in Python [IF, ELIF, ELSE] 
Python :: Python OrderedDict - LRU 
Python :: python change font in 1 line 
Python :: how to change the starting number for the loop count in pythin 
Python :: a string varible in python 
Python :: random.randint(0 1) 
Python :: Multiple page UI within same window UI PyQt 
Python :: include" is not definedP 
Python :: how to test webhook in python.py 
Python :: what is the difference between max-width and flex-basis 
Python :: Jupyter get cell output 
Python :: flask example 
Python :: merge python list items by index one after one 
Python :: is 2 an even number 
Python :: sns nan matrix 
Python :: loop through dataframe and assign values based on previous row 
Python :: install first person controller python 
Python :: should i learn c++ or python 
Python :: numpy move columns 
Python :: ORing two cv mat objects 
Python :: comment arrêter un jeu en appuyant sur une touche python 
Python :: how to fix invalid salt in python flask 
Python :: sklearn recognising sentences 
Python :: qtile: latest development version 
Python :: fibonacci sequence python code 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =