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)