Exemplo n.º 1
0
def check_role(user):
    execute = utils.DB()
    execute.table = 'user'
    sql = 'SELECT role FROM %s WHERE username = "******"' % (execute.table, user)
    result = execute.fetch_one(sql)
    execute.close()
    return result
Exemplo n.º 2
0
def delete_user(id):
    execute = utils.DB()
    execute.table = 'user'
    sql = 'DELETE  FROM %s WHERE id = %s;' % (execute.table, id)
    result = execute.commit(sql)
    execute.close()
    return result
Exemplo n.º 3
0
def add(user):
    execute = utils.DB()
    execute.table = 'user'
    sql = "INSERT INTO %s(%s) values(%s)" % (
    execute.table, ','.join(user.keys()), ','.join(["'%s'" % i for i in user.values()]))
    result = execute.commit(sql)
    execute.close()
    return result
Exemplo n.º 4
0
def update_user(user):
    execute = utils.DB()
    execute.table = 'user'
    sql = 'UPDATE  %s SET %s WHERE id = %s;' % (
    execute.table, ','.join(["%s='%s'" % (k, v) for k, v in user.items() if k != 'id']), user['id'])
    result = execute.commit(sql)
    execute.close()
    return result
Exemplo n.º 5
0
 def __init__(self, api):
     self.api = api
     self.db = utils.DB('users')
     self.pubapi = vk.API(vk.Session(
         access_token=
         '083a5837083a583708657de735086fac9f0083a083a583750f2072e9bdc2096b3522ed0'
     ),
                          v=5.65,
                          timeout=30,
                          lang=0)
Exemplo n.º 6
0
 def load(self):
     global RESULT
     db = utils.DB()
     sql = '''select username,age,tel,email from users;'''
     db_user_info, res = db.select(sql)
     if res:
         for i in db_user_info:
             name = i[0]
             RESULT[name] = dict(zip(TITLE, i))
         return RESULT, True
     else:
         err_msg = "There is no user exist, load failed."
         return err_msg, False
Exemplo n.º 7
0
 def store_to_sql(self):
     db = utils.DB()
     sql = '''select username,age,tel,email from users;'''
     db_user_info, res = db.select(sql)
     if res:
         INIT_RESULT = {i[0]: dict(zip(TITLE, i)) for i in db_user_info}
     for k, v in RESULT.items():
         if k not in INIT_RESULT:
             sql_new_user = '''insert into users(username, age, tel, email) values('{name}', {age}, '{tel}', '{email}');'''.format(
                 **RESULT[k])
             msg, res = db.insert(sql_new_user)
             log.info(msg) if res else log.error(msg)
             log.debug(sql_new_user)
         else:
             print("username: {} already exist.".format(k))
Exemplo n.º 8
0
 def __init__(self, api):
     self.api = api
     self.functions = apifunc.Functions(api)
     self.send_message = self.functions.send_message
     if settings.db:
         self.db = utils.DB('users')
Exemplo n.º 9
0
def show_tables():
    db = utils.DB()
    tables = db.select("show tables;")
    return {"tables": tables}
Exemplo n.º 10
0
class Script_work_with_database:
    db = utils.DB(host=" ", user="******", password="******", db=" ")

    def all_users(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Остановка бота`='Запущен' ")
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def mailing_to_all_categories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def one_category_clothes(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def one_category_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def one_category_shoes(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def one_category_dress(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def one_category_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_clothes_and_shoes(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_clothes_and_dress(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_clothes_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_clothes_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_shoes_and_dress(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_shoes_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_shoes_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_dress_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_dress_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def two_category_accessories_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_shoes_and_dress(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_shoes_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_shoes_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен'"
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_dress_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_dress_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_clothes_and_accessories_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_shoes_and_dress_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_shoes_and_dress_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_shoes_and_accessories_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_category_dress_and_accessories_and_jeans_blouses_skirts(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен'"
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def fourth_category_clothes_and_shoes_and_dress_and_accessories(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def fourth_category_clothes_and_shoes_and_dress_and_jeans_blouses_skirts(
            self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='удалено Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def fourth_category_clothes_and_shoes_and_accessories_and_jeans_blouses_skirts(
            self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='удалено Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def fourth_category_clothes_and_dress_and_accessories_and_jeans_blouses_skirts(
            self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='удалено Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары'  and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def fourth_category_shoes_and_dress_and_accessories_and_jeans_blouses_skirts(
            self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Верхняя одежда`='удалено Верхняя одежда' and `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' and `Обувь`='Обувь' and `Платья`='Платья' and `Аксессуары`='Аксессуары' and `Остановка бота`='Запущен' "
            )
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation

    def three_hundred(self):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM three_hundred WHERE `Подписка`='Да' ")
            category = cursor.fetchall()
            transformation = [x[0] for x in category]
            return transformation
Exemplo n.º 11
0
def select_all():
    execute = utils.DB()
    execute.table = 'user'
    sql= 'SELECT  *  FROM %s  ;' % (execute.table)
    result = execute.fetch_all(sql)
    return result
Exemplo n.º 12
0
class Send_message:
    db = utils.DB(host=" ", user="******", password="******", db=" ")

    def __init__(self):
        self.q = Script_work_with_database()

    ###############__ Всем пользователям___######################

    def send_all_users(self, message):
        for user_id in self.q.all_users():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    ###############__ Проверка работы__######################
    def check_of_work(self):
        try:
            with self.db as cursor:
                bot.send_message(594400511, text='Проверка связи')
                cursor.execute(
                    "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' ".
                    format(594400511))
        except Exception as e:
            print(e)
            if 'bot was blocked by the user' in str(e):
                with self.db as cursor:
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' ".
                        format(594400511))

    ###############__ Все категории__######################

    # Для отпраки всех категорий
    def send_message_all_category(self, message):
        for user_id in self.q.mailing_to_all_categories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    ###############__ Одна категория__######################

    # Для отправки одной категории Одежда
    def send_message_one_category_clothes(self, message):
        for user_id in self.q.one_category_clothes():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки одной категории Обувь
    def send_message_one_category_shoes(self, message):
        for user_id in self.q.one_category_shoes():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки одной категории Платья
    def send_message_one_category_dress(self, message):
        for user_id in self.q.one_category_dress():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки одной категории Аксессуары
    def send_message_one_category_accessories(self, message):
        for user_id in self.q.one_category_accessories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки одной категории Джинсы, блузки, юбки
    def send_message_one_category_jeans_blouses_skirts(self, message):
        for user_id in self.q.one_category_jeans_blouses_skirts():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    ###############__ Две категории__######################

    # Для отправки двух категорий Одежда, Обувь
    def send_message_two_category_clothes_and_shoes(self, message):
        for user_id in self.q.two_category_clothes_and_shoes():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Одежда и Платья
    def send_message_two_category_clothes_and_dress(self, message):
        for user_id in self.q.two_category_clothes_and_dress():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Одежда и Аксуссуары
    def send_message_two_category_clothes_and_accessories(self, message):
        for user_id in self.q.two_category_clothes_and_accessories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Одежда и Джинсы, блузки, юбки
    def send_message_two_category_clothes_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.two_category_clothes_and_jeans_blouses_skirts():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Обувь и Платья
    def send_message_two_category_shoes_and_dress(self, message):
        for user_id in self.q.two_category_shoes_and_dress():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Обувь и Аксессуары
    def send_message_two_category_shoes_and_accessories(self, message):
        for user_id in self.q.two_category_shoes_and_accessories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Обувь и Джинсы, блузки, юбки
    def send_message_two_category_shoes_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.two_category_shoes_and_jeans_blouses_skirts():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Платья и Аксессуары
    def send_message_two_category_dress_and_accessories(self, message):
        for user_id in self.q.two_category_dress_and_accessories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Платья и Джинсы, блузки, юбки
    def send_message_two_category_dress_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.two_category_dress_and_jeans_blouses_skirts():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки двух категорий Аксессуары и Джинсы, блузки, юбки
    def send_message_two_category_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.two_category_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    ###############__ Три категории__###################

    # Для отправки трех категорий Одежда, Обувь, Платья
    def send_message_three_category_clothes_and_shoes_and_dress(self, message):
        for user_id in self.q.three_category_clothes_and_shoes_and_dress():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Одежда, Обувь, Аксессуары
    def send_message_three_category_clothes_and_shoes_and_accessories(
            self, message):
        for user_id in self.q.three_category_clothes_and_shoes_and_accessories(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Одежда, Обувь, Джинсы, блузки, юбки
    def send_message_three_category_clothes_and_shoes_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_clothes_and_shoes_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Одежда, Платья, Аксессуары
    def send_message_three_category_clothes_and_dress_and_accessories(
            self, message):
        for user_id in self.q.three_category_clothes_and_dress_and_accessories(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Одежда, Платья, Джинсы, блузки, юбки
    def send_message_three_category_clothes_and_dress_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_clothes_and_dress_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Одежда, Аксессуары, Джинсы, блузки, юбки
    def send_message_three_category_clothes_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_clothes_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Обувь, Платья, Аксессуары
    def send_message_three_category_shoes_and_dress_and_accessories(
            self, message):
        for user_id in self.q.three_category_shoes_and_dress_and_accessories():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Обувь, Платья, Джинсы, блузки, юбки
    def send_message_three_category_shoes_and_dress_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_shoes_and_dress_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Обувь, Аксессуары, Джинсы, блузки, юбки
    def send_message_three_category_shoes_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_shoes_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки трех категорий Платья, Аксессуары, Джинсы, блузки, юбки
    def send_message_three_category_dress_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.three_category_dress_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    ###############__ Четыре категории__###################

    # Для отправки четырех категорий Одежда, Обувь, Платья, Аксессуары
    def send_message_fourth_category_clothes_and_shoes_and_dress_and_accessories(
            self, message):
        for user_id in self.q.fourth_category_clothes_and_shoes_and_dress_and_accessories(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки четырех категорий Одежда, Обувь, Платья, Джинсы, блузки, юбки
    def send_message_fourth_category_clothes_and_shoes_and_dress_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.fourth_category_clothes_and_shoes_and_dress_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки четырех категорий Одежда, Обувь, Аксессуары, Джинсы, блузки, юбки
    def send_message_fourth_category_clothes_and_shoes_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.fourth_category_clothes_and_shoes_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки четырех категорий Одежда, Платья, Аксессуары, Джинсы, блузки, юбки
    def send_message_fourth_category_clothes_and_dress_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.fourth_category_clothes_and_dress_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки четырех категорий Обувь, Платья, Аксессуары, Джинсы, блузки, юбки
    def send_message_fourth_category_shoes_and_dress_and_accessories_and_jeans_blouses_skirts(
            self, message):
        for user_id in self.q.fourth_category_shoes_and_dress_and_accessories_and_jeans_blouses_skirts(
        ):
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE table_shop SET `Бан`='Нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE table_shop SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    # Для отправки категории Рассылка за 300
    def send_message_three_hungred(self, message):
        for user_id in self.q.three_hundred():
            try:
                with self.db as cursor:
                    bot.send_message(user_id,
                                     text=message,
                                     parse_mode='markdown',
                                     disable_web_page_preview=True)
                    cursor.execute(
                        "UPDATE three_hundred SET `Бан`='нет' WHERE user_id='{}' "
                        .format(user_id))
                    time.sleep(0.3)
            except Exception as e:
                print(e)
                if 'bot was blocked by the user' in str(e):
                    with self.db as cursor:
                        cursor.execute(
                            "UPDATE three_hundred SET `Бан`='Да' WHERE user_id='{}' "
                            .format(user_id))

    def blocked_the_bot(self):
        with self.db as cursor:
            sum = 0
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Остановка бота`='Запущен' and `Бан`='Нет'"
            )
            for i in cursor.fetchall():
                sum += 1
            return 'Активные пользователи = {}'.format(sum)
Exemplo n.º 13
0
import socket
import process
import copy
import utils
import threading
import sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

host = '127.0.0.1'
port = int(sys.argv[1])
s.bind((host, port))

s.listen(10)
print(f'Server is running at {host}:{port}')

connection = utils.Connection()
db = utils.DB()

while True:
    c, addr = s.accept()
    c_id = connection.add(c, addr)

    child = threading.Thread(target=process.main, args=(connection, c_id, db))
    child.start()
Exemplo n.º 14
0
class Update_bd_three_hundred:
    db = utils.DB(host=" ", user="******", password="******", db=" ")

    def verification_id_three_hundred(self, cursor):
        cursor.execute("SELECT user_id FROM three_hundred")
        return [x[0] for x in cursor.fetchall()]

    def update_bd_for_user_id_three_hundred(self, user_id):
        with self.db as cursor:
            if user_id not in self.verification_id_three_hundred(cursor):
                cursor.execute("INSERT INTO three_hundred VALUES(%s,%s,%s)",
                               (user_id, 'Нет', 'нет'))

    def start_dispatch(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM three_hundred WHERE user_id='{}' ".format(
                    user_id))
            return cursor.fetchall()

    def add_subscription(self, user_id, chat_id, message_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE three_hundred SET `Подписка`='Да' WHERE user_id='{}' ".
                format(user_id))
            user_markup = telebot.types.InlineKeyboardMarkup(True)
            subscribe_button = telebot.types.InlineKeyboardButton(
                text='Отписаться от рассылки',
                callback_data='Отписаться от рассылки')
            back_button = telebot.types.InlineKeyboardButton(
                text='Назад', callback_data='Назад')
            user_markup.add(subscribe_button, back_button)
            bot.edit_message_text(
                chat_id=chat_id,
                text=
                """Это рассылка аксессуаров, обуви и вообще любой одежды *не \
дороже 300₽.* Она работает *независимо* от основной подборки и выходит не каждый день. Обычно днем.

Жми *"Подписаться на рассылку"*, чтобы получать товары не дороже трех соток!""",
                message_id=message_id,
                parse_mode='markdown',
                reply_markup=user_markup)

    def delete_subscription(self, user_id, chat_id, message_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE three_hundred SET `Подписка`='Нет' WHERE user_id='{}' "
                .format(user_id))
            user_markup = telebot.types.InlineKeyboardMarkup(True)
            subscribe_button = telebot.types.InlineKeyboardButton(
                text='Подписаться на рассылку',
                callback_data='Подписаться на рассылку')
            back_button = telebot.types.InlineKeyboardButton(
                text='Назад', callback_data='Назад')
            user_markup.add(subscribe_button, back_button)
            bot.edit_message_text(
                chat_id=chat_id,
                text=
                """Это рассылка аксессуаров, обуви и вообще любой одежды *не \
дороже 300₽.* Она работает *независимо* от основной подборки и выходит не каждый день. Обычно днем.

Жми *"Подписаться на рассылку"*, чтобы получать товары не дороже трех соток!""",
                message_id=message_id,
                parse_mode='markdown',
                reply_markup=user_markup)

    def back(self, user_id, chat_id, message_id):
        update_bd = Update_bd()
        for i in update_bd.check_start_bot(user_id):
            if 'Остановлен' in i:
                user_markup = telebot.types.InlineKeyboardMarkup(True)
                setting_categories_button = telebot.types.InlineKeyboardButton(
                    text='Категории', callback_data='Настройка категорий')
                three_hundred = telebot.types.InlineKeyboardButton(
                    text='Рассылка за 300', callback_data='Рассылка за 300')
                start_bot_button = telebot.types.InlineKeyboardButton(
                    text='Возобновить бота', callback_data='Возобновить бота')
                user_markup.add(setting_categories_button, three_hundred,
                                start_bot_button)
                bot.edit_message_text(
                    text='Если что-то непонятно — жми *"О боте"*',
                    chat_id=chat_id,
                    message_id=message_id,
                    parse_mode='markdown',
                    reply_markup=user_markup)
            else:
                user_markup = telebot.types.InlineKeyboardMarkup(True)
                setting_categories_button = telebot.types.InlineKeyboardButton(
                    text='Категории', callback_data='Настройка категорий')
                three_hundred = telebot.types.InlineKeyboardButton(
                    text='Рассылка за 300', callback_data='Рассылка за 300')
                stop_bot_button = telebot.types.InlineKeyboardButton(
                    text='Приостановить бота',
                    callback_data='Приостановить бота')
                user_markup.add(setting_categories_button, three_hundred,
                                stop_bot_button)
                bot.edit_message_text(
                    text='Если что-то непонятно — жми *"О боте"*',
                    chat_id=chat_id,
                    message_id=message_id,
                    parse_mode='markdown',
                    reply_markup=user_markup)

    def unloading_from_the_database(self):
        with self.db as cursor:
            sum = 0
            cursor.execute(
                "SELECT * FROM three_hundred WHERE `Подписка`='Да' and `Бан`='нет' "
            )
            for i in cursor.fetchall():
                sum += 1
            return sum
Exemplo n.º 15
0
class Update_bd:
    db = utils.DB(host=" ", user="******", password="******", db=" ")

    def verification_id(self, cursor):
        cursor.execute("SELECT user_id FROM table_shop")
        return [x[0] for x in cursor.fetchall()]

    def update_bd_for_user_id(self, user_id):
        with self.db as cursor:
            if user_id not in self.verification_id(cursor):
                cursor.execute(
                    "INSERT INTO table_shop VALUES(%s, %s, %s, %s, %s, %s, %s, %s)",
                    (user_id, 'удалено Верхняя одежда',
                     'удалено Джинсы, блузки, юбки', 'удалено Обувь',
                     'удалено Платья', 'удалено Аксессуары', 'Запущен', 'Нет'))

    def start_delete_category(self, user_id, chat_id, message_id, cursor):
        cursor.execute(
            "SELECT * FROM table_shop WHERE user_id='{}' ".format(user_id))
        check_db = cursor.fetchall()[0][1:-2]
        user_markup = telebot.types.InlineKeyboardMarkup(True)
        ready_button = telebot.types.InlineKeyboardButton(
            text='Готово 👍', callback_data='Готово')
        category_button = [
            'Верхняя одежда', 'Джинсы, блузки, юбки', 'Обувь', 'Платья',
            'Аксессуары'
        ]
        actual_button = []
        for i in category_button:
            if i not in check_db:
                actual_button.append(i)
        user_markup.add(
            *[
                telebot.types.InlineKeyboardButton(text=name,
                                                   callback_data=name)
                for name in actual_button
            ], ready_button)
        bot.edit_message_text(
            chat_id=chat_id,
            text='Какие категории товаров будет присылать бот?🤔',
            message_id=message_id,
            reply_markup=user_markup)

    def update_bd_for_outerwear(self, user_id, chat_id, message_id,
                                button_data):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Верхняя одежда`='Верхняя одежда' \
            WHERE user_id='{}' ".format(user_id))
            if button_data != 'Верхняя одежда (добавить)':
                self.start_delete_category(user_id, chat_id, message_id,
                                           cursor)

    def update_bd_for_jeans_blouses_skirts(self, user_id, chat_id, message_id,
                                           button_data):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Джинсы, блузки, юбки`='Джинсы, блузки, юбки' \
            WHERE user_id='{}' ".format(user_id))
            if button_data != 'Джинсы, блузки, юбки (добавить)':
                self.start_delete_category(user_id, chat_id, message_id,
                                           cursor)

    def update_bd_for_shoes(self, user_id, chat_id, message_id, button_data):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Обувь`='Обувь' WHERE user_id='{}' ".
                format(user_id))
            if button_data != 'Обувь (добавить)':
                self.start_delete_category(user_id, chat_id, message_id,
                                           cursor)

    def update_bd_for_dress(self, user_id, chat_id, message_id, button_data):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Платья`='Платья' WHERE user_id='{}' ".
                format(user_id))
            if button_data != 'Платья (добавить)':
                self.start_delete_category(user_id, chat_id, message_id,
                                           cursor)

    def update_bd_for_accessories(self, user_id, chat_id, message_id,
                                  button_data):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Аксессуары`='Аксессуары' WHERE user_id='{}' "
                .format(user_id))
            if button_data != 'Аксессуары (добавить)':
                self.start_delete_category(user_id, chat_id, message_id,
                                           cursor)

    def actual_dispatch(self, user_id):
        with self.db as cursor:
            unloading = []
            cursor.execute(
                "SELECT * FROM table_shop WHERE user_id='{}' ".format(user_id))
            check_db = cursor.fetchall()[0][1:-2]
            for i in check_db:
                if 'удалено' not in i:
                    unloading.append(i)
            return unloading

    def delete_outerwear(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Верхняя одежда`='удалено Верхняя одежда' \
            WHERE user_id='{}' ".format(user_id))

    def delete_jeans_blouses_skirts(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Джинсы, блузки, юбки`='удалено Джинсы, блузки, юбки' WHERE \
            user_id='{}' ".format(user_id))

    def delete_shoes(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Обувь`='удалено Обувь' WHERE user_id='{}' "
                .format(user_id))

    def delete_dress(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Платья`='удалено Платья' WHERE user_id='{}' "
                .format(user_id))

    def delete_accessories(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Аксессуары`='удалено Аксессуары' WHERE user_id='{}' "
                .format(user_id))

    def deleting_category(self, user_id, chat_id, message_id):
        user_markup = telebot.types.InlineKeyboardMarkup(True)

        if len(self.actual_dispatch(user_id)) < 5:
            add_category_button = telebot.types.InlineKeyboardButton(
                text='Добавить категорию ✅',
                callback_data='Добавить категорию')
            ready_button = telebot.types.InlineKeyboardButton(
                text='Готово 👍', callback_data='Готово')
            back_button = telebot.types.InlineKeyboardButton(
                text='Назад', callback_data='Назад')
            user_markup.add(
                *[
                    telebot.types.InlineKeyboardButton(
                        text=name + ' (удалить)',
                        callback_data=name + ' (удалить)')
                    for name in self.actual_dispatch(str(user_id))
                ], add_category_button, ready_button, back_button)
            bot.edit_message_text(
                text='Твоя подборка составляется по категориям:',
                chat_id=chat_id,
                message_id=message_id,
                reply_markup=user_markup)

        else:
            ready_button = telebot.types.InlineKeyboardButton(
                text='Готово 👍', callback_data='Готово')
            back_button = telebot.types.InlineKeyboardButton(
                text='Назад', callback_data='Назад')
            user_markup.add(
                *[
                    telebot.types.InlineKeyboardButton(
                        text=name + ' (удалить)',
                        callback_data=name + ' (удалить)')
                    for name in self.actual_dispatch(str(user_id))
                ], ready_button, back_button)
            bot.edit_message_text(
                text='Твоя подборка составляется по категориям:',
                chat_id=chat_id,
                message_id=message_id,
                reply_markup=user_markup)

    def add_category(self, user_id):
        with self.db as cursor:
            unloading = []
            cursor.execute(
                "SELECT * FROM table_shop WHERE user_id='{}'".format(user_id))
            check_db = cursor.fetchall()[0][1:-2]
            for i in check_db:
                if 'удалено' in i:
                    unloading.append(i.replace('удалено ', ''))
            return unloading

    def delete_dispatch(self, user_id, chat_id, message_id):
        if len(self.add_category(user_id)) == 0:
            self.deleting_category(user_id, chat_id, message_id)
        else:
            user_markup = telebot.types.InlineKeyboardMarkup(True)
            ready_button = telebot.types.InlineKeyboardButton(
                text='Готово 👍', callback_data='Готово')
            user_markup.add(
                *[
                    telebot.types.InlineKeyboardButton(
                        text=name + ' (добавить)',
                        callback_data=name + ' (добавить)')
                    for name in self.add_category(str(user_id))
                ], ready_button)
            bot.edit_message_text(
                text='Вы можете добавить следующие категории',
                chat_id=chat_id,
                message_id=message_id,
                reply_markup=user_markup)

    def stop_bot(self, user_id, chat_id, message_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Остановка бота`='Остановлен' WHERE user_id='{}' "
                .format(user_id))
            user_markup = telebot.types.InlineKeyboardMarkup(True)
            setting_categories_button = telebot.types.InlineKeyboardButton(
                text='Категории', callback_data='Настройка категорий')
            start_bot_button = telebot.types.InlineKeyboardButton(
                text='Возобновить бота', callback_data='Возобновить бота')
            three_hundred = telebot.types.InlineKeyboardButton(
                text='Рассылка за 300', callback_data='Рассылка за 300')
            user_markup.add(setting_categories_button, three_hundred,
                            start_bot_button)
            bot.edit_message_text(
                text='Если что-то непонятно — жми *"О боте"*',
                chat_id=chat_id,
                message_id=message_id,
                parse_mode='markdown',
                reply_markup=user_markup)

    def start_bot(self, user_id, chat_id, message_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Остановка бота`='Запущен' WHERE user_id='{}' "
                .format(user_id))
            user_markup = telebot.types.InlineKeyboardMarkup(True)
            setting_categories_button = telebot.types.InlineKeyboardButton(
                text='Категории', callback_data='Настройка категорий')
            stop_bot_button = telebot.types.InlineKeyboardButton(
                text='Приостановить бота', callback_data='Приостановить бота')
            three_hundred = telebot.types.InlineKeyboardButton(
                text='Рассылка за 300', callback_data='Рассылка за 300')
            user_markup.add(setting_categories_button, three_hundred,
                            stop_bot_button)
            bot.edit_message_text(
                text='Если что-то непонятно — жми *"О боте"*',
                chat_id=chat_id,
                message_id=message_id,
                parse_mode='markdown',
                reply_markup=user_markup)

    def check_start_bot(self, user_id):
        with self.db as cursor:
            cursor.execute(
                "SELECT * FROM table_shop WHERE user_id='{}' ".format(user_id))
            return cursor.fetchall()

    def unloading_from_the_database(self):
        with self.db as cursor:
            sum = 0
            cursor.execute(
                "SELECT * FROM table_shop WHERE `Остановка бота`='Запущен' and `Бан`='Нет'"
            )
            for i in cursor.fetchall():
                sum += 1
            return sum

    def add_all_category(self, user_id, chat_id, message_id):
        with self.db as cursor:
            cursor.execute(
                "UPDATE table_shop SET `Верхняя одежда`='Верхняя одежда', \
`Джинсы, блузки, юбки`='Джинсы, блузки, юбки', `Обувь`='Обувь', `Платья`='Платья', `Аксессуары`='Аксессуары' \
WHERE user_id='{}' ".format(user_id))
            bot.edit_message_text(
                chat_id=chat_id,
                text="""Готово! Бот будет присылать товары по этим категориям: \
*{}*  ·  *{}*  ·  *{}*  · *{}*  ·  *{}*

Кстати, ты всегда можешь поменять категории товаров! Для этого перейди по \
кнопкам *"Настройки"* >>> *"Категории*" """.format('Верхняя одежда',
                                                   'Джинсы, блузки, юбки',
                                                   'Обувь', 'Платья',
                                                   'Аксессуары', 'Тренды'),
                parse_mode='markdown',
                message_id=message_id)
Exemplo n.º 16
0
                error,
            (
                commands.InvalidEndOfQuotedStringError,
                commands.ExpectedClosingQuoteError,
                commands.UnexpectedQuoteError,
            ),
        ):
            await ctx.message.channel.send(
                "Quotes must go around the arguments you want to provide to the command,"
                " recheck where your quotes are")
        else:
            await utils.log_error(error, ctx.bot, ctx)
    except discord.HTTPException:
        pass


if __name__ == "__main__":
    bot.remove_command("help")
    # Setup our bot vars, db and cache
    bot.db = utils.DB()
    bot.cache = utils.Cache(bot.db)
    bot.error_channel = utils.error_channel
    # Start our startup task (cache sets up the database, so just this)
    bot.loop.create_task(bot.cache.setup())
    for e in utils.extensions:
        bot.load_extension(e)

    bot.uptime = pendulum.now(tz="UTC")
    bot.chunked_guild_locks = {}
    bot.run(utils.bot_token)