send report in python added, UTF encoding voor windows update
This commit is contained in:
68
send_report.py
Normal file
68
send_report.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/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)
|
||||
@@ -8,8 +8,17 @@ import mysql.connector
|
||||
from datetime import datetime, timedelta
|
||||
import argparse
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
os.environ['PYTHONIOENCODING'] = 'utf-8'
|
||||
|
||||
# Forceer UTF-8 encoding voor stdout/stderr op Windows
|
||||
if sys.platform == 'win32':
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
|
||||
|
||||
class SteVeReporter:
|
||||
def __init__(self, host: str, database: str, user: str, password: str, port: int = 3306,
|
||||
price_host: str = None, price_port: int = None, price_user: str = None, price_password: str = None):
|
||||
|
||||
Reference in New Issue
Block a user