- исправлении логики определения последней версии
This commit is contained in:
42
site_api.py
42
site_api.py
@@ -153,46 +153,60 @@ class SiteAPI:
|
|||||||
def check_script_versions(self, content_processor):
|
def check_script_versions(self, content_processor):
|
||||||
"""Проверка и публикация новых версий скриптов"""
|
"""Проверка и публикация новых версий скриптов"""
|
||||||
self.logger.info("Проверяем новые версии скриптов")
|
self.logger.info("Проверяем новые версии скриптов")
|
||||||
|
|
||||||
# Получаем changelog
|
# Получаем changelog
|
||||||
matches_changelog, last_changelog, resp_changelog = self.get_changelog()
|
matches_changelog, last_changelog, resp_changelog = self.get_changelog()
|
||||||
if not matches_changelog or not last_changelog:
|
if not matches_changelog or not last_changelog:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Получаем существующие новости
|
# Получаем существующие новости
|
||||||
news_list = self.get_news()
|
news_list = self.get_news()
|
||||||
|
|
||||||
# Извлекаем номера версий из заголовков новостей
|
# Извлекаем номера версий из заголовков новостей
|
||||||
pattern = re.compile(r'Кумулятивное обновление скриптов (\d+)')
|
pattern = re.compile(r'Кумулятивное обновление скриптов (\d+)')
|
||||||
|
|
||||||
def extract_number(title):
|
def extract_number(title):
|
||||||
match = pattern.search(title)
|
match = pattern.search(title)
|
||||||
return int(match.group(1)) if match else None
|
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]
|
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:
|
if numbers:
|
||||||
last_topics_script = max(numbers)
|
last_topics_script = max(numbers)
|
||||||
self.logger.info(f"Последняя новость на сайте о версии: {last_topics_script}")
|
self.logger.info(f"Последняя новость на сайте о версии: {last_topics_script}")
|
||||||
|
|
||||||
if last_topics_script >= last_changelog:
|
if last_topics_script >= last_changelog:
|
||||||
self.logger.warning("Нет новых версий скриптов PortProton")
|
self.logger.warning("Нет новых версий скриптов PortProton")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.logger.warning("На сайте нет новостей о скриптах")
|
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}")
|
self.logger.info(f"Найдена новая версия скрипта {script_ver}")
|
||||||
|
|
||||||
post_text, post_data = self.create_script_update_post(
|
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:
|
if post_data:
|
||||||
self.logger.debug(f"Публикуем {post_data}")
|
self.logger.debug(f"Публикуем {post_data}")
|
||||||
self.post_to_site(post_data)
|
self.post_to_site(post_data)
|
Reference in New Issue
Block a user