From 821c1a8e018e5313afb2a93b3dd8a3854a793715 Mon Sep 17 00:00:00 2001 From: Marius Mutu Date: Thu, 6 Nov 2025 21:30:54 +0200 Subject: [PATCH] =?UTF-8?q?Adaug=C4=83=20progress=20updates=20pentru=20/sc?= =?UTF-8?q?rape=5Fzip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modificări: - telegram_trigger_bot.py: - Păstrează TELEGRAM_CHAT_ID și TELEGRAM_MESSAGE_ID pentru progress - Setează flag SEND_AS_ZIP=true în environment - NU mai dezactivează notificările - notifications.py: - Verifică flag SEND_AS_ZIP din environment - Dacă SEND_AS_ZIP=true, trimite ZIP cu progress updates - Mesajul de progres e editat la fel ca /scrape normal Comportament /scrape_zip: 1. Bot trimite "Scraper pornit (arhiva ZIP)" 2. Scraper rulează și editează mesajul cu progress 3. notifications.py detectează flag-ul SEND_AS_ZIP 4. Trimite ZIP cu solduri în loc de fișiere individuale 5. Editează mesajul final cu detalii despre ZIP 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- notifications.py | 8 ++++++++ telegram_trigger_bot.py | 19 ++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/notifications.py b/notifications.py index 9859c7a..1c1fbd6 100644 --- a/notifications.py +++ b/notifications.py @@ -6,6 +6,7 @@ Handles email and Discord notifications with file attachments import smtplib import logging import zipfile +import os from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase @@ -220,6 +221,13 @@ class TelegramNotifier: logging.info(f"Received telegram_message_id: {telegram_message_id}, telegram_chat_id: {telegram_chat_id}") logging.info(f"Stored progress_message_id: {self.progress_message_id}, progress_chat_id: {self.progress_chat_id}") + # Check if SEND_AS_ZIP flag is set (from Telegram bot /scrape_zip command) + send_as_zip = os.getenv('SEND_AS_ZIP', 'false').lower() == 'true' + + if send_as_zip: + logging.info("SEND_AS_ZIP flag detected - sending as ZIP archive") + return self._send_with_zip(files, accounts) + # Check total file size total_size = sum(Path(f).stat().st_size for f in files if Path(f).exists()) diff --git a/telegram_trigger_bot.py b/telegram_trigger_bot.py index 8647521..f28c48c 100644 --- a/telegram_trigger_bot.py +++ b/telegram_trigger_bot.py @@ -121,14 +121,16 @@ class TelegramTriggerBot: env = os.environ.copy() env['PLAYWRIGHT_BROWSERS_PATH'] = 'C:\\playwright-browsers' - # Dacă send_as_zip, dezactivează notificările - bot-ul va trimite ZIP-ul manual - if send_as_zip: - env['ENABLE_NOTIFICATIONS'] = 'false' - logging.info("Notificări dezactivate - bot va trimite ZIP manual") - elif message_id: + # Setează progress updates pentru Telegram + if message_id: env['TELEGRAM_CHAT_ID'] = str(chat_id) env['TELEGRAM_MESSAGE_ID'] = str(message_id) logging.info(f"Setting environment: TELEGRAM_CHAT_ID={chat_id}, TELEGRAM_MESSAGE_ID={message_id}") + + # Dacă send_as_zip, comunică să trimită ZIP în loc de fișiere individuale + if send_as_zip: + env['SEND_AS_ZIP'] = 'true' + logging.info("Mod ZIP activat - va trimite arhivă ZIP") else: logging.warning("No message_id available for progress updates") @@ -143,12 +145,7 @@ class TelegramTriggerBot: if result.returncode == 0: logging.info("Scraper finalizat cu succes") - - # Dacă send_as_zip, trimite ZIP manual - if send_as_zip: - logging.info("Trimitere rezultate ca ZIP...") - self.send_zip_files(chat_id, reply_to_message_id) - # Altfel, mesajul final va fi editat de notifications.py + # Mesajul final va fi editat de notifications.py (cu ZIP sau fișiere individuale) else: # Eroare