Compare commits
2 Commits
bc353308b5
...
c2ca401a26
| Author | SHA1 | Date | |
|---|---|---|---|
| c2ca401a26 | |||
| 821c1a8e01 |
@@ -6,6 +6,7 @@ Handles email and Discord notifications with file attachments
|
|||||||
import smtplib
|
import smtplib
|
||||||
import logging
|
import logging
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import os
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.base import MIMEBase
|
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"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}")
|
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
|
# Check total file size
|
||||||
total_size = sum(Path(f).stat().st_size for f in files if Path(f).exists())
|
total_size = sum(Path(f).stat().st_size for f in files if Path(f).exists())
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Telegram Trigger Bot - Declanșează BTGO Scraper prin comandă Telegram
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import io
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
@@ -25,6 +26,10 @@ CHAT_ID = os.getenv('TELEGRAM_CHAT_ID')
|
|||||||
POLL_TIMEOUT = int(os.getenv('TELEGRAM_POLL_TIMEOUT', 60)) # Default 60 secunde
|
POLL_TIMEOUT = int(os.getenv('TELEGRAM_POLL_TIMEOUT', 60)) # Default 60 secunde
|
||||||
|
|
||||||
# Logging - force stdout instead of stderr (for Windows service logging)
|
# Logging - force stdout instead of stderr (for Windows service logging)
|
||||||
|
# Set UTF-8 encoding for stdout to support Romanian characters
|
||||||
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||||
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='[%(asctime)s] [%(levelname)s] %(message)s',
|
format='[%(asctime)s] [%(levelname)s] %(message)s',
|
||||||
@@ -121,14 +126,16 @@ class TelegramTriggerBot:
|
|||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['PLAYWRIGHT_BROWSERS_PATH'] = 'C:\\playwright-browsers'
|
env['PLAYWRIGHT_BROWSERS_PATH'] = 'C:\\playwright-browsers'
|
||||||
|
|
||||||
# Dacă send_as_zip, dezactivează notificările - bot-ul va trimite ZIP-ul manual
|
# Setează progress updates pentru Telegram
|
||||||
if send_as_zip:
|
if message_id:
|
||||||
env['ENABLE_NOTIFICATIONS'] = 'false'
|
|
||||||
logging.info("Notificări dezactivate - bot va trimite ZIP manual")
|
|
||||||
elif message_id:
|
|
||||||
env['TELEGRAM_CHAT_ID'] = str(chat_id)
|
env['TELEGRAM_CHAT_ID'] = str(chat_id)
|
||||||
env['TELEGRAM_MESSAGE_ID'] = str(message_id)
|
env['TELEGRAM_MESSAGE_ID'] = str(message_id)
|
||||||
logging.info(f"Setting environment: TELEGRAM_CHAT_ID={chat_id}, TELEGRAM_MESSAGE_ID={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:
|
else:
|
||||||
logging.warning("No message_id available for progress updates")
|
logging.warning("No message_id available for progress updates")
|
||||||
|
|
||||||
@@ -143,12 +150,7 @@ class TelegramTriggerBot:
|
|||||||
|
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
logging.info("Scraper finalizat cu succes")
|
logging.info("Scraper finalizat cu succes")
|
||||||
|
# Mesajul final va fi editat de notifications.py (cu ZIP sau fișiere individuale)
|
||||||
# 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
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Eroare
|
# Eroare
|
||||||
|
|||||||
Reference in New Issue
Block a user