From 89f2c5f3f1d2eaa63a96143e0cae689513dc34f9 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: Sun, 26 May 2024 12:24:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE=D1=81=D1=8F=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D1=82=D0=B0=20=D0=B2=20=D0=B4=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- news-bot.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/news-bot.py b/news-bot.py index 08e37dd..1a3532c 100755 --- a/news-bot.py +++ b/news-bot.py @@ -73,6 +73,16 @@ def script_content(script_ver, resp_changelog): soup = make_soup(resp_changelog) page_text = str(soup) page_text = page_text.replace("Вы можете помочь развитию проекта: https://linux-gaming.ru/donate/", '') + + # Удаляем несколько различных вхождений с помощью регулярных выражений + patterns_to_remove = [ + r'###Scripts version \d+###', + r'\d{4}×\d{3} \d+ KB', + r'/tag/scripts' + ] + for pattern in patterns_to_remove: + page_text = re.sub(pattern, '', page_text) + # Находим текст до определенного текста, тега или класса (например, до тега
) last_text = f"###Scripts version {script_ver - 1}" last_text = str(last_text) @@ -109,7 +119,7 @@ def script_content(script_ver, resp_changelog): def news_content(post_id): - logging.info(f"Запрос содержимого поста новости с ID: {post_id}") + logging.debug(f"Запрос содержимого поста новости с ID: {post_id}") response = response_get(f"https://linux-gaming.ru/t/{post_id}.json") if response and response.status_code == 200: topic_data = response.json() @@ -167,8 +177,7 @@ def news(): '«Новости»')] return filtered_list_titles_and_ids else: - logging.error(f"Ошибка при запросе тем с сайта: {resp_topics.status_code if resp_topics else - 'Нет доступа к сайту'}") + logging.error(f"Ошибка при запросе тем с сайта: {resp_topics.status_code if resp_topics else 'Нет доступа к сайту'}") return [] @@ -281,10 +290,12 @@ def check_discord_public(): for topic_id, topic_title in list_titles_and_ids: if topic_title not in discord_messages: list_for_public.append((topic_id, topic_title)) - if list_for_public != []: - logging.info(f"Новости для публикации в дискорд: {list_for_public}") - else: + if not list_for_public: logging.info(f"Новостей для публикации в дискорд нет") + await client.close() + else: + logging.info(f"Новости для публикации в дискорд: {list_for_public}") + channel = client.get_channel(channel_id) if not channel: logging.error(f"ID канала Discord {channel_id} не существует") @@ -301,7 +312,7 @@ def check_discord_public(): # Разбиваем содержимое на части по 4000 символов for i in range(0, len(content), 4000): await channel.send(content[i:i+4000]) - + await client.close() client.run(keys.discord_token)