From b760035af993635ae0fa8c0cb74e6209aad577f4 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Fri, 31 Oct 2025 16:36:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D1=8D=D0=B3=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BF=D1=83?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8=20=D0=92=D0=9A?= =?UTF-8?q?-=D0=BF=D0=BE=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 ++ vk_load.py | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.env b/.env index e1225b7..ff04d41 100644 --- a/.env +++ b/.env @@ -55,6 +55,8 @@ RESPONDER_BOT_NAME = "posto_1638_bot" # Tag to detect org info # Org info is normally long, publish without picture ORG_MESSAGE_TAG = "#оргинфаЗиланткона" +# tag to detect posts to not repost from VK +VK_NO_REPOST_TAG = "#окоЗиланта" # Minutes delay before publishing an event diff --git a/vk_load.py b/vk_load.py index 623e92d..f09072a 100644 --- a/vk_load.py +++ b/vk_load.py @@ -18,6 +18,7 @@ VK_ACCESS_TOKEN = os.getenv('VK_ACCESS_TOKEN', '') VK_API_VERSION = os.getenv('VK_API_VERSION', '5.131') IS_EVENT = os.getenv('IS_EVENT', 'false').lower() in ('true', '1', 'yes', 'on') AUTO_PUBLISH = os.getenv('AUTO_PUBLISH', 'false').lower() in ('true', '1', 'yes', 'on') +VK_NO_REPOST_TAG = os.getenv('VK_NO_REPOST_TAG', '') # Тег для отключения автопубликации LOG_FILE = os.getenv('LOG_FILE', 'vk_loader.log') # Путь к лог-файлу LOG_PREFIX = "VK_loader" # Уникальный префикс для идентификации скрипта @@ -144,6 +145,14 @@ def save_to_database(posts): new_posts_count = 0 for post in posts: try: + # Проверка наличия тега VK_NO_REPOST_TAG в тексте поста + post_text = post.get('text', '') + should_auto_publish = AUTO_PUBLISH + + if VK_NO_REPOST_TAG and VK_NO_REPOST_TAG in post_text: + # Если тег найден, отключаем автопубликацию независимо от AUTO_PUBLISH + should_auto_publish = False + # Добавляем поля is_event, marked_for_publication, shortname и action_number cursor.execute(''' INSERT INTO posts ( @@ -164,14 +173,20 @@ def save_to_database(posts): int(post['poll_multiple']), post['poll_end_date'], IS_EVENT, - int(AUTO_PUBLISH), # Значение из .env + int(should_auto_publish), # Значение с учетом проверки тега None, # shortname - пока не используется, устанавливаем NULL None # action_number - пока не используется, устанавливаем NULL )) if cursor.rowcount > 0: new_posts_count += 1 - # Логируем добавление нового поста - log_message(f"Добавлен новый пост: ID {post['vk_post_id']}, Дата: {post['published_at']}, Автопубликация: {'Да' if AUTO_PUBLISH else 'Нет'}") + # Логируем добавление нового поста с указанием причины отключения автопубликации + auto_publish_reason = 'Да' + if not should_auto_publish: + if VK_NO_REPOST_TAG and VK_NO_REPOST_TAG in post_text: + auto_publish_reason = 'Нет (найден тег ' + VK_NO_REPOST_TAG + ')' + else: + auto_publish_reason = 'Нет' + log_message(f"Добавлен новый пост: ID {post['vk_post_id']}, Дата: {post['published_at']}, Автопубликация: {auto_publish_reason}") except mysql.connector.Error as err: error_msg = f"Ошибка при вставке поста {post['vk_post_id']}: {err}" log_message(error_msg)