diff --git a/notifications.py b/notifications.py
index a01d13d..9859c7a 100644
--- a/notifications.py
+++ b/notifications.py
@@ -23,13 +23,13 @@ class EmailNotifier:
self.config = config
self.enabled = config.EMAIL_ENABLED
- def send(self, files: List[str], account_count: int) -> bool:
+ def send(self, files: List[str], accounts: list) -> bool:
"""
Send email with CSV attachments
Args:
files: List of file paths to attach
- account_count: Number of accounts processed
+ accounts: List of account data with balances
Returns:
True if successful, False otherwise
@@ -51,7 +51,7 @@ class EmailNotifier:
msg['Subject'] = f'BTGO Scraper Results - {datetime.now().strftime("%Y-%m-%d %H:%M")}'
# Email body
- body = self._create_email_body(files, account_count)
+ body = self._create_email_body(files, accounts)
msg.attach(MIMEText(body, 'html'))
# Attach files
@@ -67,7 +67,7 @@ class EmailNotifier:
# Check size limit (10MB typical SMTP limit)
if total_size > 10 * 1024 * 1024:
logging.warning(f"Email attachments exceed 10MB, creating ZIP archive")
- return self._send_with_zip(files, account_count)
+ return self._send_with_zip(files, accounts)
with open(file_path, 'rb') as f:
part = MIMEBase('application', 'octet-stream')
@@ -94,7 +94,7 @@ class EmailNotifier:
logging.error(f"Failed to send email: {e}")
return False
- def _send_with_zip(self, files: List[str], account_count: int) -> bool:
+ def _send_with_zip(self, files: List[str], accounts: list) -> bool:
"""Send email with files compressed as ZIP"""
try:
# Create ZIP archive
@@ -114,7 +114,7 @@ class EmailNotifier:
msg['To'] = self.config.EMAIL_TO
msg['Subject'] = f'BTGO Scraper Results (ZIP) - {datetime.now().strftime("%Y-%m-%d %H:%M")}'
- body = self._create_email_body([str(zip_path)], account_count, is_zip=True)
+ body = self._create_email_body([str(zip_path)], accounts, is_zip=True)
msg.attach(MIMEText(body, 'html'))
with open(zip_path, 'rb') as f:
@@ -137,19 +137,39 @@ class EmailNotifier:
logging.error(f"Failed to send email with ZIP: {e}")
return False
- def _create_email_body(self, files: List[str], account_count: int, is_zip: bool = False) -> str:
+ def _create_email_body(self, files: List[str], accounts: list, is_zip: bool = False) -> str:
"""Create HTML email body"""
file_list = '
'.join([f'• {Path(f).name}' for f in files])
file_count = 1 if is_zip else len(files)
+ # Calculate total balance
+ total_ron = sum(acc['sold'] for acc in accounts if acc.get('moneda') == 'RON')
+
+ # Build account balance list
+ account_balances = ""
+ for acc in accounts:
+ nume = acc['nume_cont']
+ sold = acc['sold']
+ moneda = acc['moneda']
+ account_balances += f'
Execution time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
-Accounts processed: {account_count}
+Accounts processed: {len(accounts)}
Files attached: {file_count}
| TOTAL | +{total_ron:,.2f} RON | +