Exemplo n.º 1
0
def add_item(item, user):
    global result
    db = sqlite.connect("clientbase.db")
    cur = db.cursor()
    cur.execute("SELECT * FROM items WHERE (name) = (?)", (item.name,))
    print(cur.fetchone())
    if not cur.fetchone():
        try:
            cur.execute("INSERT INTO items "
                        "(type, name, company, price, description, url, wc, seller_name) "
                        "VALUES (?,?,?,?,?,?,?,?)",
                        (
                            item.type,
                            item.name,
                            item.company,
                            item.price,
                            item.description,
                            item.url,
                            item.wc,
                            user.username))
            print('\nadded\n')
            result = 'Имя: ' + str(item.type) + '\n' + 'Почта: ' + str(item.name) + '\n' + 'Назначение помещения: '\
                     + str(item.company) + '\n' + 'Состояние: ' + str(item.price) +\
                     '\n' + 'Площадь: ' + str(item.description) + '\n' + 'Количество комнат: ' + str(item.url) + '\n'\
                     + 'Количество санузлов: ' + str(item.wc) + '\n' + 'Никнейм: @' + str(user.username)
            db.commit()
        except Exception as e:
            config.log(Error=e, Text='ADDING_NEW_ITEM_ERROR')
Exemplo n.º 2
0
 def set_data(self, *args):
     try:
         self.name = args[0]
         self.company = args[1]
         self.price = args[2]
         self.description = args[3]
         self.url = args[4]
         self.wc
     except Exception as e:
         config.log(Error=e, text="SET_DATA_ERROR_OCCURED")
Exemplo n.º 3
0
def add_kat(message):
    db = sqlite.connect("clientbase.db")
    cur = db.cursor()
    cur.execute("SELECT * FROM categories WHERE (name) = (?)", (message.text,))
    if not cur.fetchone():
        try:
            cur.execute("INSERT INTO categories"
                        "(name)"
                        "VALUES (?)",
                        ((message.text),))
            db.commit()
            print("added")
        except Exception as e:
            config.log(Error=e, Text='ADDING_NEW_CATEGORY_ERROR')
Exemplo n.º 4
0
 def set_full_data(self, *args):
     try:
         self.id = args[0]
         self.type = args[1]
         self.name = args[2]
         self.company = args[3]
         self.price = args[4]
         self.description = args[5]
         self.url = args[6]
         self.wc = args[7]
         self.seller = args[8]
         print('seller is ' + str(self.seller))
     except Exception as e:
         config.log(Error=e, text="SET_DATA_ERROR_OCCURED")
Exemplo n.º 5
0
def add_item(item, user_id):
    db = sqlite.connect("clientbase.db")
    cur = db.cursor()
    cur.execute("SELECT * FROM items WHERE (name) = (?)", (item.get_name(),))
    print(cur.fetchone())
    if not cur.fetchone():
        try:
            cur.execute("INSERT INTO items "
                        "(type, name, company, price, description, url, wc, seller_name) "
                        "VALUES (?,?,?,?,?,?,?,?)",
                        (item.type, item.name, item.company, item.price, item.description, item.url, item.wc,
                         item.seller))
            db.commit()
        except Exception as e:
            config.log(Error=e, Text='ADDING_NEW_ITEM_ERROR')
Exemplo n.º 6
0
def add_client(message):
    db = sqlite.connect("clientbase.db")
    cur = db.cursor()
    login = message.text[1:]
    try:
        cur.execute("SELECT * FROM clients WHERE user_id = (?)", (message.from_user.id,))
    except Exception as e:
        config.log(Error=e, Text="DBTESTING ERROR")
    if not cur.fetchone():
        try:
            cur.execute("INSERT INTO clients (user_id) VALUES (?)", (message.from_user.id,))
            config.log(Text="Client successfully added",
                       user=str(message.from_user.first_name + " " + message.from_user.last_name))
        except Exception as e:
            config.log(Error=e, Text="CLIENT_ADDING_ERROR")
        db.commit()
    else:
        config.log(Error="IN_THE_BASE_YET",
                   id=message.from_user.id,
                   info=str(message.from_user.last_name) + " " + str(message.from_user.first_name),
                   username=message.from_user.username)
Exemplo n.º 7
0
@bot.message_handler(
    func=lambda message: base.get_user_step(message.chat.id) == "Enter wc")
def handle_add_item_wc(message):
    sent = bot.send_message(message.chat.id, "Количество санузлов")
    bot.register_next_step_handler(sent, base.add_item_wc)
    const.user_adding_item_step[message.chat.id] = "End"


# Конец добавления заявки
@bot.message_handler(
    func=lambda message: base.get_user_step(message.chat.id) == "End")
def handle_add_item_end(message):
    bot.send_message(message.chat.id, "Ваша заявка принята.")
    bot.send_message(const.admin_id, base.result)
    const.user_adding_item_step.pop(message.chat.id)


# Запуск бота

while True:
    try:
        bot.polling(none_stop=True, interval=0)
    except ConnectionError as expt:
        config.log(Exception='HTTP_CONNECTION_ERROR', text=expt)
        print('Connection lost..')
        time.sleep(30)
        continue
    except r_exceptions.Timeout as exptn:
        config.log(Exception='HTTP_REQUEST_TIMEOUT_ERROR', text=exptn)
        time.sleep(5)
        continue