Compare commits

...

2 Commits

Author SHA1 Message Date
c2ca401a26 Fix UnicodeEncodeError pe Windows pentru caractere românești
Problema:
- Logging eșua cu UnicodeEncodeError când scria caractere românești (ă, î, ș)
- Windows cmd.exe folosește cp1252 implicit, nu UTF-8

Soluție:
- Forțare encoding UTF-8 pentru stdout și stderr
- Folosește io.TextIOWrapper cu encoding='utf-8'
- errors='replace' pentru caractere care nu pot fi encodate

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 21:31:55 +02:00
821c1a8e01 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>
2025-11-06 21:30:54 +02:00
2 changed files with 21 additions and 11 deletions

View File

@@ -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())

View File

@@ -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