Adaugă trimitere ZIP pe email și elimină emoji-uri din mesaje
- /scrape_zip trimite ZIP pe ambele canale (Telegram + email) - /zip trimite ZIP și pe email, nu doar pe Telegram - Elimină emoji-uri din mesajele Telegram user-facing - Adaugă ghid "NO EMOJIS" în CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,13 @@ class EmailNotifier:
|
||||
logging.error("Email configuration incomplete")
|
||||
return False
|
||||
|
||||
# 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 email with ZIP archive")
|
||||
return self._send_with_zip(files, accounts)
|
||||
|
||||
# Create message
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = self.config.EMAIL_FROM
|
||||
@@ -138,6 +145,64 @@ class EmailNotifier:
|
||||
logging.error(f"Failed to send email with ZIP: {e}")
|
||||
return False
|
||||
|
||||
def send_existing_zip(self, zip_path: Path, accounts: list) -> bool:
|
||||
"""
|
||||
Send email with existing ZIP file
|
||||
|
||||
Args:
|
||||
zip_path: Path to existing ZIP file
|
||||
accounts: List of account data with balances
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
if not self.enabled:
|
||||
logging.info("Email notifications disabled")
|
||||
return False
|
||||
|
||||
try:
|
||||
# Validate config
|
||||
if not all([self.config.SMTP_SERVER, self.config.EMAIL_FROM, self.config.EMAIL_TO]):
|
||||
logging.error("Email configuration incomplete")
|
||||
return False
|
||||
|
||||
if not zip_path.exists():
|
||||
logging.error(f"ZIP file not found: {zip_path}")
|
||||
return False
|
||||
|
||||
# Create message
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = self.config.EMAIL_FROM
|
||||
msg['To'] = self.config.EMAIL_TO
|
||||
msg['Subject'] = f'BTGO Export (ZIP) - {datetime.now().strftime("%Y-%m-%d %H:%M")}'
|
||||
|
||||
# Email body
|
||||
body = self._create_email_body([str(zip_path)], accounts, is_zip=True)
|
||||
msg.attach(MIMEText(body, 'html'))
|
||||
|
||||
# Attach ZIP file
|
||||
with open(zip_path, 'rb') as f:
|
||||
part = MIMEBase('application', 'zip')
|
||||
part.set_payload(f.read())
|
||||
encoders.encode_base64(part)
|
||||
part.add_header('Content-Disposition', f'attachment; filename={zip_path.name}')
|
||||
msg.attach(part)
|
||||
|
||||
# Send email
|
||||
logging.info(f"Sending email with existing ZIP to {self.config.EMAIL_TO}...")
|
||||
with smtplib.SMTP(self.config.SMTP_SERVER, self.config.SMTP_PORT) as server:
|
||||
server.starttls()
|
||||
if self.config.SMTP_USERNAME and self.config.SMTP_PASSWORD:
|
||||
server.login(self.config.SMTP_USERNAME, self.config.SMTP_PASSWORD)
|
||||
server.send_message(msg)
|
||||
|
||||
logging.info(f"✓ Email with ZIP sent successfully to {self.config.EMAIL_TO}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to send email with existing ZIP: {e}")
|
||||
return False
|
||||
|
||||
def _create_email_body(self, files: List[str], accounts: list, is_zip: bool = False) -> str:
|
||||
"""Create HTML email body"""
|
||||
file_list = '<br>'.join([f'• {Path(f).name}' for f in files])
|
||||
|
||||
Reference in New Issue
Block a user