#!/usr/bin/env python3 import os import subprocess import smtplib import os import argparse from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from datetime import datetime os.environ['PYTHONIOENCODING'] = 'utf-8' # Parse command line arguments parser = argparse.ArgumentParser(description='Genereer en verstuur laadrapport') parser.add_argument('--transaction', type=int, help='Specifieke transactie ID') parser.add_argument('--limit', type=int, default=1, help='Aantal transacties (default: 1)') args = parser.parse_args() # Configuratie TO_EMAIL = "mark@markkors.nl" FROM_EMAIL = "laadpaal@raspberry.local" SUBJECT = f"Laadrapport {datetime.now().strftime('%d-%m-%Y')}" # SMTP configuratie SMTP_SERVER = "192.168.178.201" SMTP_PORT = 25 # Genereer rapport commando cmd = [ 'python', 'steve_transaction_report.py', '--host', '192.168.178.201', '--port', '3307', '--user', 'steve', '--password', 'kS9R*xp17ZwCD@CV&E^N', '--price-user', 'alfen_user', '--price-password', '5uVgr%f%s2P5GR@3q!', ] # Voeg optionele parameters toe if args.transaction: cmd.extend(['--transaction', str(args.transaction)]) else: cmd.extend(['--limit', str(args.limit)]) try: # BELANGRIJK: encoding='utf-8' toevoegen om UTF-8 correct te lezen op Windows report = subprocess.check_output(cmd, encoding='utf-8') except subprocess.CalledProcessError as e: print(f"✗ Fout bij genereren rapport: {e}") exit(1) # Email samenstellen msg = MIMEMultipart() msg['From'] = FROM_EMAIL msg['To'] = TO_EMAIL msg['Subject'] = SUBJECT msg['Content-Type'] = 'text/plain; charset=utf-8' msg.attach(MIMEText(report, 'plain', 'utf-8')) # Verstuur email try: with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server: server.send_message(msg) print(f"✓ Rapport verzonden naar {TO_EMAIL}") except Exception as e: print(f"✗ Fout bij verzenden: {e}") exit(1)