xakmika
Проверенные
		- Сообщения
- 173
- Реакции
- -5
- Баллы
- 11,015
Ребят, у меня в json заготовленные темы, заголовок и описание, я добавил через код в таблицу xf_thread он добавился но на сайте нету его, и интернете искал и не нашёл нечего.
	
	
	
		
				
			
		Python:
	
	import mysql.connector
from mysql.connector import Error
# Данные для подключения к базе данных
db_config = {
    'host': ' ',       # Хост базы данных
    'database': ' ',            # Название базы данных
    'user': ' ',                   # Имя пользователя
    'password': ' ' # Ваш пароль
}
# Данные для добавления в таблицу xf_thread
thread_data = {
    'node_id': 36,
    'title': 'Новая тема с Python',
    'reply_count': 0,
    'view_count': 0,
    'user_id': 1,
    'username': 'admin',
    'post_date': 1731321980,
    'sticky': 0,
    'discussion_state': 'visible',
    'discussion_open': 1,
    'discussion_type': b'\x64\x69\x73\x63\x75\x73\x73\x69\x6f\x6e',
    'type_data': b'\x5b\x5d',
    'index_state': 'not_indexed',
    'first_post_id': 4,
    'first_post_reaction_score': 0,
    'first_post_reactions': b'\x5b\x5d',
    'last_post_date': 1731675980,
    'last_post_id': 7,
    'last_post_user_id': 1,
    'last_post_username': 'admin',
    'prefix_id': 4,
    'tags': b'\x5b\x5d',
    'custom_fields': b'\x5b\x5d',
    'vote_score': 0,
    'vote_count': 0,
    'featured': 0,
    'is_sticked': 0,
    'tg_ct_color': None,
    'tg_ct_end': None,
    'bump_thread_disabled': 0
}
def insert_thread():
    connection = None  # Инициализируем переменную для подключения
    try:
        # Устанавливаем соединение с базой данных
        connection = mysql.connector.connect(**db_config)
        if connection.is_connected():
            cursor = connection.cursor()
            # Запрос для добавления новой записи
            insert_query = """
                INSERT INTO xf_thread (node_id, title, reply_count, view_count, user_id, username, post_date, sticky,
                                       discussion_state, discussion_open, discussion_type, type_data, index_state,
                                       first_post_id, first_post_reaction_score, first_post_reactions, last_post_date,
                                       last_post_id, last_post_user_id, last_post_username, prefix_id, tags, custom_fields,
                                       vote_score, vote_count, featured, is_sticked, tg_ct_color, tg_ct_end, bump_thread_disabled)
                VALUES (%(node_id)s, %(title)s, %(reply_count)s, %(view_count)s, %(user_id)s, %(username)s, %(post_date)s,
                        %(sticky)s, %(discussion_state)s, %(discussion_open)s, %(discussion_type)s, %(type_data)s, %(index_state)s,
                        %(first_post_id)s, %(first_post_reaction_score)s, %(first_post_reactions)s, %(last_post_date)s,
                        %(last_post_id)s, %(last_post_user_id)s, %(last_post_username)s, %(prefix_id)s, %(tags)s,
                        %(custom_fields)s, %(vote_score)s, %(vote_count)s, %(featured)s, %(is_sticked)s, %(tg_ct_color)s,
                        %(tg_ct_end)s, %(bump_thread_disabled)s)
            """
            # Выполняем запрос с данными
            cursor.execute(insert_query, thread_data)
            # Подтверждаем изменения в базе данных
            connection.commit()
            print("Новая тема успешно добавлена!")
    except Error as e:
        print(f"Ошибка при работе с базой данных: {e}")
    finally:
        if connection and connection.is_connected():
            cursor.close()
            connection.close()
            print("Соединение с базой данных закрыто.")
if __name__ == "__main__":
    insert_thread() 
				 
						
 
 
		 
 
		
 
 
		 
 
		 
 
		 
 
		