- исправлении логики определения последней версии

This commit is contained in:
2025-09-30 20:16:45 +03:00
parent 5d2bdfb746
commit b1d7a909db

View File

@@ -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)