From caebebf3cf8d1a0590dbb05f4fbe53eec5def304 Mon Sep 17 00:00:00 2001 From: itexpert228 <67105314+fdaser1337@users.noreply.github.com> Date: Sun, 22 Feb 2026 20:40:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=92=D0=9E=20=D0=95=D0=91=D0=90=D0=A2?= =?UTF-8?q?=D0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 19 ++++++++++++++++++- zparser.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 zparser.py diff --git a/main.py b/main.py index d591d18..739060d 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,7 @@ from aiogram.client.default import DefaultBotProperties from PIL import Image, ImageDraw, ImageFont from datetime import datetime, time, timedelta from zoneinfo import ZoneInfo +from zparser import get_military_data # Базовые пути/настройки проекта. BASE_DIR = Path(__file__).parent @@ -692,6 +693,20 @@ async def handle_zvetok(message: Message): await message.answer(result) +async def handle_svodka(message: Message): + channel = "creamy_caprice" + data = get_military_data(channel, depth=5) + + if data["status"] == "success": + response = ( + f"в период с {data['dates']} хохлы в среднем проебывали по {data['pace']} км² в сутки, " + f"а за день ВС РФ лишала чубатых в среднем по {data['total']} км²" + ) + await message.answer(response) + else: + await message.answer(f"Хохлы ответят за это...: {data['message']}") + + def main(): # Точка входа: создаём бота, регистрируем команды и запускаем polling. token = os.getenv("BOT_TOKEN") @@ -718,6 +733,8 @@ def main(): BotCommand(command="fetch", description="цены (новый источник)"), BotCommand(command="zvetok", description="Цветянский бля"), BotCommand(command="talk", description="Побазарить"), + BotCommand(command="svodka", description="СВО: итоги"), + ] ) except Exception: # noqa: WPS440 @@ -737,7 +754,7 @@ def main(): dp.message.register(handle_fetch, Command("fetch")) dp.message.register(handle_zvetok, Command("zvetok")) dp.message.register(handle_talk, Command("talk")) - + dp.message.register(handle_svodka, Command("svodka")) async def handle_gen_mem_cmd(message: Message, bot: Bot): diff --git a/zparser.py b/zparser.py new file mode 100644 index 0000000..838df4a --- /dev/null +++ b/zparser.py @@ -0,0 +1,55 @@ +import requests +from bs4 import BeautifulSoup +import re +import time + +def get_military_data(channel_username, depth=5): + headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'} + last_id = None + + for i in range(depth): + url = f"https://t.me/s/{channel_username}" + if last_id: + url += f"?before={last_id}" + + try: + response = requests.get(url, headers=headers, timeout=10) + soup = BeautifulSoup(response.text, 'html.parser') + messages = soup.find_all('div', class_='tgme_widget_message') + + if not messages: + break + + first_msg_data = messages[0].get('data-post') + if first_msg_data: + last_id = first_msg_data.split('/')[-1] + + for msg in reversed(messages): + text_elem = msg.find('div', class_='tgme_widget_message_text') + if not text_elem: + continue + + text = " ".join(text_elem.get_text(separator=' ').split()) + text_lower = text.lower() + + if "темп" in text_lower and "продвижения" in text_lower: + # Улучшенная регулярка для дат (ловит и "с 14 по 17", и "с 14 февраля по 17 февраля") + dates_match = re.search(r"с (.*?)(?=\.|\s+темп)", text_lower) + # Твои регулярки для цифр — отличные + pace_match = re.search(r"темп[^+-]*([+-]\d+[.,]\d+)", text_lower) + total_match = re.search(r"общее продвижение\s*(\d+[.,]\d+)", text_lower) + + if pace_match: + return { + "status": "success", + "dates": dates_match.group(1).strip() if dates_match else "не указаны", + "pace": pace_match.group(1).replace(',', '.'), + "total": total_match.group(1).replace(',', '.') if total_match else "0", + "post_id": msg.get('data-post').split('/')[-1] + } + time.sleep(1) + except Exception as e: + print(f"Ошибка на итерации {i}: {e}") + continue + + return {"status": "error", "message": "Сводка не найдена в последних постах"} \ No newline at end of file -- 2.45.2