Adaugă progress updates pentru /scrape_zip
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user