From b1d7a909dbdac602aba618defdf0a0b2105e8236 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:16:45 +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 --- site_api.py | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/site_api.py b/site_api.py index c4ea194..36b6e39 100644 --- a/site_api.py +++ b/site_api.py @@ -153,46 +153,60 @@ class SiteAPI: def check_script_versions(self, content_processor): """Проверка и публикация новых версий скриптов""" self.logger.info("Проверяем новые версии скриптов") - + # Получаем changelog matches_changelog, last_changelog, resp_changelog = self.get_changelog() if not matches_changelog or not last_changelog: return - + # Получаем существующие новости news_list = self.get_news() - + # Извлекаем номера версий из заголовков новостей pattern = re.compile(r'Кумулятивное обновление скриптов (\d+)') - + def extract_number(title): match = pattern.search(title) return int(match.group(1)) if match else None - + numbers = [extract_number(title) for _, title in news_list if extract_number(title) is not None] - + + published_versions = set(numbers) if numbers else set() + if numbers: last_topics_script = max(numbers) self.logger.info(f"Последняя новость на сайте о версии: {last_topics_script}") - + if last_topics_script >= last_changelog: self.logger.warning("Нет новых версий скриптов PortProton") return else: self.logger.warning("На сайте нет новостей о скриптах") - + # Публикуем новые версии - self._publish_new_script_versions(matches_changelog, resp_changelog, content_processor) + self._publish_new_script_versions(matches_changelog, published_versions, resp_changelog, content_processor) - def _publish_new_script_versions(self, matches_changelog, resp_changelog, content_processor): + def _publish_new_script_versions(self, matches_changelog, published_versions, resp_changelog, content_processor): """Публикация новых версий скриптов""" - for script_ver, next_version in zip(reversed(matches_changelog[:-1]), reversed(matches_changelog[1:])): + # Сортируем версии в порядке возрастания + sorted_versions = sorted([int(v) for v in matches_changelog]) + + # Проходим по версиям в порядке от старых к новым + for i in range(len(sorted_versions) - 1): + script_ver = int(sorted_versions[i]) + next_version = int(sorted_versions[i + 1]) + + # Пропускаем уже опубликованные версии + if script_ver in published_versions: + self.logger.debug(f"Версия скрипта {script_ver} уже опубликована на сайте, пропускаем") + continue + self.logger.info(f"Найдена новая версия скрипта {script_ver}") - + post_text, post_data = self.create_script_update_post( - script_ver, next_version, resp_changelog, content_processor + str(script_ver), str(next_version), resp_changelog, content_processor ) - + if post_data: self.logger.debug(f"Публикуем {post_data}") self.post_to_site(post_data) \ No newline at end of file