From 6b0c8a05b9d6f539919b6725eea1756a3dc7ea83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=A5=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Tue, 30 Sep 2025 20:55:43 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content_processor.py | 58 ++++++++++++++++++++++++++++++++++---------- site_api.py | 18 ++++++++++---- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/content_processor.py b/content_processor.py index 38f2e6e..0af62bf 100644 --- a/content_processor.py +++ b/content_processor.py @@ -171,20 +171,49 @@ class ContentProcessor: def create_script_content(self, script_ver, next_version, response): """Создание контента для обновления скрипта""" - self.logger.debug(f"Создаем контент для версии скрипта {script_ver}") + self.logger.debug(f"Создаем контент для версии скрипта от {script_ver} до {next_version}") soup = self.make_soup(response) page_text = str(soup) page_text = page_text.replace("Вы можете помочь развитию проекта: https://linux-gaming.ru/donate/", '') - last_text = f"###Scripts version {next_version}### / stable" - index_last_text = page_text.find(last_text) + # В changelog версии идут от новых к старым (2444, 2443, 2442...) + # Нужно найти текущую версию (next_version) и предыдущую (script_ver) + # Предыдущая версия находится ПОСЛЕ текущей в файле + + current_text = f"###Scripts version {next_version}### / stable" + self.logger.debug(f"Ищем текущую версию: {current_text}") + index_current = page_text.find(current_text) + self.logger.debug(f"Индекс текущей версии: {index_current}") + + if index_current != -1: + # Ищем предыдущую версию ПОСЛЕ текущей + text_after_current = page_text[index_current:] + + # Попробуем разные варианты формата предыдущей версии + possible_formats = [ + f"###Scripts version {script_ver}### / stable", + f"###Scripts version {script_ver}###", + f"Scripts version {script_ver}" + ] + + index_prev_relative = -1 + for prev_text in possible_formats: + self.logger.debug(f"Ищем предыдущую версию (формат): {prev_text}") + index_prev_relative = text_after_current.find(prev_text) + if index_prev_relative != -1: + self.logger.debug(f"Найдено! Относительный индекс: {index_prev_relative}") + break + + if index_prev_relative == -1: + self.logger.error(f"Не найдена версия {script_ver} после версии {next_version}") + self.logger.debug(f"Первые 1000 символов после текущей версии: {text_after_current[:1000]}") + return None + + # Извлекаем текст от начала текущей версии до начала предыдущей + index_prev = index_current + index_prev_relative + changelog_text = page_text[index_current:index_prev] + self.logger.debug(f"Длина извлеченного текста: {len(changelog_text)} символов") - if index_last_text != -1: - changelog_text_last = page_text[:index_last_text] - prev_text = f"###Scripts version {script_ver}### / stable" - index_script_ver = changelog_text_last.find(prev_text) - changelog_text = changelog_text_last[index_script_ver:] - changelog_text = re.sub( r'###Scripts version (\d+)### / Дата: (\d{2}\.\d{2}\.\d{4}) / Размер скачиваемого обновления: \d+ \S+', r'\1 - \2' + ":", @@ -195,10 +224,13 @@ class ContentProcessor: r'\1 - \2' + ":", changelog_text ) - + post_text = "-----------------------------\n" + changelog_text - - self.logger.debug(f"Возвращаем post_text: {post_text}") + + self.logger.debug(f"Возвращаем post_text длиной {len(post_text)} символов") return post_text - + else: + self.logger.error(f"Не найдена версия {next_version} в changelog (конец диапазона)") + return None + return None \ No newline at end of file diff --git a/site_api.py b/site_api.py index e09f5f4..ccd585f 100644 --- a/site_api.py +++ b/site_api.py @@ -204,16 +204,24 @@ class SiteAPI: self.logger.info(f"Будем публиковать версии начиная с индекса {start_index}") # Публикуем только новые версии после последней опубликованной - for i in range(start_index, len(sorted_versions) - 1): - script_ver = int(sorted_versions[i]) - next_version = int(sorted_versions[i + 1]) + # Идём до последнего элемента включительно + for i in range(start_index, len(sorted_versions)): + current_version = int(sorted_versions[i]) + # Для changelog берём предыдущую версию как начало диапазона + prev_version = int(sorted_versions[i - 1]) if i > 0 else None - self.logger.info(f"Найдена новая версия скрипта {script_ver}") + if prev_version is None: + self.logger.warning(f"Нет предыдущей версии для {current_version}, пропускаем") + continue + + self.logger.info(f"Публикуем новость о версии {current_version} (changelog от {prev_version} до {current_version})") post_text, post_data = self.create_script_update_post( - str(script_ver), str(next_version), resp_changelog, content_processor + str(prev_version), str(current_version), resp_changelog, content_processor ) if post_data: + # Заголовок должен быть с текущей версией + post_data['title'] = f"Кумулятивное обновление скриптов {current_version}" self.logger.debug(f"Публикуем {post_data}") self.post_to_site(post_data) \ No newline at end of file