Начало изменений для новостей о stable скриптах
This commit is contained in:
85
news-bot.py
85
news-bot.py
@@ -22,7 +22,7 @@ url_post = "https://linux-gaming.ru/posts.json"
|
|||||||
url_news = f"https://linux-gaming.ru/c/news/6.json"
|
url_news = f"https://linux-gaming.ru/c/news/6.json"
|
||||||
url_vk_post = "https://api.vk.com/method/wall.post"
|
url_vk_post = "https://api.vk.com/method/wall.post"
|
||||||
url_vk_get = "https://api.vk.com/method/wall.get"
|
url_vk_get = "https://api.vk.com/method/wall.get"
|
||||||
url_changelog = "https://gitlab.eterfund.ru/Castro-Fidel/PortWINE/raw/master/data_from_portwine/changelog_ru"
|
url_changelog = "https://gitlab.eterfund.ru/Castro-Fidel/PortWINE/raw/devel/data_from_portwine/changelog_ru"
|
||||||
|
|
||||||
heads_site = {
|
heads_site = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -199,37 +199,38 @@ def extract_links(text):
|
|||||||
return url_pattern
|
return url_pattern
|
||||||
|
|
||||||
|
|
||||||
def script_content(script_ver, resp_changelog):
|
def script_content(last_topics_script, last_changelog, resp_changelog):
|
||||||
logging.debug(f"Вход в script_content")
|
logging.debug(f"Вход в script_content")
|
||||||
soup = make_soup(resp_changelog)
|
soup = make_soup(resp_changelog)
|
||||||
page_text = str(soup)
|
page_text = str(soup)
|
||||||
page_text = page_text.replace("Вы можете помочь развитию проекта: https://linux-gaming.ru/donate/", '')
|
page_text = page_text.replace("Вы можете помочь развитию проекта: https://linux-gaming.ru/donate/", '')
|
||||||
|
|
||||||
# Находим текст до определенного текста, тега или класса (например, до тега <hr>)
|
changelog_text = ""
|
||||||
last_text = f"###Scripts version {script_ver - 1}"
|
for script_ver in range(last_topics_script + 1, last_changelog + 1):
|
||||||
last_text = str(last_text)
|
current_ver_text = f"###Scripts version {script_ver}### / stable"
|
||||||
index_last_text = page_text.find(last_text)
|
next_ver_text = f"###Scripts version {script_ver + 1}### / stable"
|
||||||
|
|
||||||
if index_last_text != -1:
|
start_index = page_text.find(current_ver_text)
|
||||||
changelog_text_last = page_text[:index_last_text]
|
end_index = page_text.find(next_ver_text)
|
||||||
prev_text = f"###Scripts version {script_ver}"
|
|
||||||
index_script_ver = changelog_text_last.find(prev_text)
|
|
||||||
|
|
||||||
if index_script_ver != -1:
|
if start_index != -1:
|
||||||
changelog_text = changelog_text_last[index_script_ver:]
|
if end_index != -1:
|
||||||
post_text = (f"-----------------------------\n") + changelog_text
|
changelog_text += page_text[start_index:end_index]
|
||||||
site_text = (f"[center][img]/uploads/default/original/1X/5cfa59077a5275971401fab0114e56f3ffdd0ec4.png[/img]["
|
else:
|
||||||
f"/center]\n{post_text}")
|
changelog_text += page_text[start_index:]
|
||||||
|
|
||||||
logging.debug(f"Сообщение на сайт {site_text}")
|
post_text = f"-----------------------------\n{changelog_text}"
|
||||||
|
site_text = f"[center][img]/uploads/default/original/1X/5cfa59077a5275971401fab0114e56f3ffdd0ec4.png[/img][/center]\n{post_text}"
|
||||||
|
|
||||||
post_data = {
|
logging.debug(f"Сообщение на сайт {site_text}")
|
||||||
"title": f"Обновление скриптов {script_ver}",
|
|
||||||
"raw": site_text,
|
post_data = {
|
||||||
"category": keys.cat_num
|
"title": f"Обновление скриптов {last_changelog}",
|
||||||
}
|
"raw": site_text,
|
||||||
logging.debug(f"Возвращаем post_text - {post_text}\n post_data - {post_data}")
|
"category": keys.cat_num
|
||||||
return post_text, post_data, post_text
|
}
|
||||||
|
logging.debug(f"Возвращаем post_text - {post_text}\n post_data - {post_data}")
|
||||||
|
return post_text, post_data
|
||||||
|
|
||||||
|
|
||||||
def news_content(post_id):
|
def news_content(post_id):
|
||||||
@@ -265,7 +266,7 @@ def resp_change():
|
|||||||
resp_changelog = response_get(url_changelog, heads_site)
|
resp_changelog = response_get(url_changelog, heads_site)
|
||||||
|
|
||||||
if resp_changelog and resp_changelog.status_code == 200:
|
if resp_changelog and resp_changelog.status_code == 200:
|
||||||
matches_changelog = re.findall(r'###Scripts version (\d+)###', resp_changelog.text)
|
matches_changelog = re.findall(r'###Scripts version (\d+)### / stable', resp_changelog.text)
|
||||||
logging.debug(f"Найдены версии в истории изменений: {matches_changelog}")
|
logging.debug(f"Найдены версии в истории изменений: {matches_changelog}")
|
||||||
last_changelog = int(max(matches_changelog))
|
last_changelog = int(max(matches_changelog))
|
||||||
logging.info(f"Последняя версия в истории изменений: {last_changelog}")
|
logging.info(f"Последняя версия в истории изменений: {last_changelog}")
|
||||||
@@ -321,28 +322,30 @@ def check_version(last_changelog, resp_changelog):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
numbers = [extract_number(title) for _, title in list_titles_and_ids if extract_number(title) is not None]
|
numbers = [extract_number(title) for _, title in list_titles_and_ids if extract_number(title) is not None]
|
||||||
|
|
||||||
if numbers:
|
if numbers:
|
||||||
last_topics_script = max(numbers)
|
last_topics_script = max(numbers)
|
||||||
logging.info(f"Последняя новость на сайте о версии: {last_topics_script}")
|
logging.info(f"Последняя новость на сайте о версии: {last_topics_script}")
|
||||||
|
|
||||||
if last_topics_script < last_changelog:
|
|
||||||
list_new_ver = []
|
|
||||||
|
|
||||||
for script_ver in range(last_topics_script + 1, last_changelog + 1):
|
|
||||||
list_new_ver.append(script_ver)
|
|
||||||
logging.info(f"Найдена новая версия скрипта {script_ver}")
|
|
||||||
changelog_text, post_data, params = script_content(script_ver, resp_changelog)
|
|
||||||
if post_data:
|
|
||||||
logging.debug(f"Публикуем {post_data}")
|
|
||||||
site_post(url_post, heads_site, post_data)
|
|
||||||
|
|
||||||
if not list_new_ver:
|
|
||||||
logging.warning(f"Не найдена новая версия скрипта")
|
|
||||||
sys.exit()
|
|
||||||
else:
|
|
||||||
logging.warning("Нет новых версий скриптов PortProton")
|
|
||||||
else:
|
else:
|
||||||
logging.warning("На сайте нет новостей о скриптах")
|
logging.warning("На сайте нет новостей о скриптах")
|
||||||
|
last_topics_script = 0
|
||||||
|
|
||||||
|
if last_topics_script < last_changelog:
|
||||||
|
changelog_text, post_data = script_content(last_topics_script, last_changelog, resp_changelog)
|
||||||
|
if post_data:
|
||||||
|
logging.debug(f"Публикуем {post_data}")
|
||||||
|
site_post(url_post, heads_site, post_data)
|
||||||
|
else:
|
||||||
|
logging.warning("Нет новых версий скриптов PortProton")
|
||||||
|
|
||||||
|
# Публикация топиков
|
||||||
|
if not numbers or last_topics_script < last_changelog:
|
||||||
|
changelog_text, post_data = script_content(last_topics_script, last_changelog, resp_changelog)
|
||||||
|
if post_data:
|
||||||
|
logging.debug(f"Публикуем {post_data}")
|
||||||
|
site_post(url_post, heads_site, post_data)
|
||||||
|
else:
|
||||||
|
logging.warning("Нет новых версий скриптов PortProton")
|
||||||
|
|
||||||
|
|
||||||
async def discord_post(post_text, client):
|
async def discord_post(post_text, client):
|
||||||
|
Reference in New Issue
Block a user