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