diff --git a/.env b/.env index 9596018..750d5b8 100644 --- a/.env +++ b/.env @@ -9,7 +9,9 @@ E_MAIL_SMTP_SERVER_PORT="465" E_MAIL_SEND_TO="serfling@itdata-gera.de" ### SDF Einstellungen für MSSQL Importer/Exporter -SDF_LOCAL_PFAD="D:/Waagen-PC/" +#SDF_LOCAL_PFAD="D:/Waagen-PC/" +## Test Pfad +SDF_LOCAL_PFAD="C:/Users/Sebastian Serfling/PycharmProjects/Balzer-WaagenDaten/" SDF_NAME="App.sdf" ### Log Einstellungen für MSSQL Importer/Exporter diff --git a/App.sdf b/App.sdf index 0bd5949..01a89e9 100644 Binary files a/App.sdf and b/App.sdf differ diff --git a/Monitor.py b/Monitor.py index 8751847..f119af0 100644 --- a/Monitor.py +++ b/Monitor.py @@ -68,9 +68,9 @@ class LogMonitorApp(ctk.CTk): self.logo_image = ctk.CTkImage(light_image=logo_img, dark_image=logo_img, size=(120, 40)) self.logo_label = ctk.CTkLabel(self, image=self.logo_image, text='', cursor='hand2') else: - self.logo_label = ctk.CTkLabel(self, text='www.deine-website.de', text_color='skyblue', cursor='hand2') + self.logo_label = ctk.CTkLabel(self, text='www.stines.de', text_color='skyblue', cursor='hand2') self.logo_label.pack(pady=5) - self.logo_label.bind('', lambda e: webbrowser.open('https://www.deine-website.de')) + self.logo_label.bind('', lambda e: webbrowser.open('https://www.stines.de')) self.protocol('WM_DELETE_WINDOW', self.hide_to_tray) self.bind('', self.on_minimize) diff --git a/errorhandler.py b/errorhandler.py deleted file mode 100644 index 28fc84b..0000000 --- a/errorhandler.py +++ /dev/null @@ -1 +0,0 @@ -import datetime \ No newline at end of file diff --git a/mail.py b/mail.py index 2cf0ff5..07e7745 100644 --- a/mail.py +++ b/mail.py @@ -1,3 +1,49 @@ -## Import für E-Mail Server und Mail Adressen Daten -import dotenv +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart import datetime +import os +from dotenv import load_dotenv + +load_dotenv() + +# SMTP-Parameter aus .env lesen +SMTP_SERVER = os.getenv("E_MAIL_SMTP_SERVER") +SMTP_PORT = int(os.getenv("E_MAIL_SMTP_SERVER_PORT")) +SMTP_USER = os.getenv("E_MAIL_ADDRESS") +SMTP_PASS = os.getenv("E_MAIL_ADDRESS_PASSWORD") +MAIL_FROM = os.getenv("E_MAIL_SEND_TO", SMTP_USER) +MAIL_TO = os.getenv("E_MAIL_SEND_TO") + +if not all([SMTP_SERVER, SMTP_USER, SMTP_PASS, MAIL_TO]): + print("⚠️ SMTP-Konfiguration unvollständig – bitte .env prüfen.") + +def send_email(subject: str, body: str): + """Allgemeine Mail-Funktion""" + msg = MIMEMultipart() + msg["From"] = MAIL_FROM + msg["To"] = MAIL_TO + msg["Subject"] = subject + + msg.attach(MIMEText(body, "plain", "utf-8")) + + try: + with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT) as server: + print("Inside smtplib") + server.login(SMTP_USER, SMTP_PASS) + server.sendmail(MAIL_FROM, MAIL_TO.split(","), msg.as_string()) + print(f"✅ E-Mail gesendet: {subject}") + except Exception as e: + print(f"❌ Fehler beim Senden der E-Mail ({subject}): {e}") + +def send_error_email(msg: str, process: str): + """Fehlermeldung senden""" + subject = f"❌ Fehler im Prozess {process}" + body = f"Prozess: {process}\nZeit: {datetime.datetime.now()}\n\nFehlermeldung:\n{msg}" + send_email(subject, body) + +def send_report_email(msg: str, process: str): + """Erfolgreichen Abschlussbericht senden""" + subject = f"✅ Prozess abgeschlossen: {process}" + body = f"Prozess: {process}\nZeit: {datetime.datetime.now()}\n\nErgebnisbericht:\n{msg}" + send_email(subject, body) diff --git a/mssqlconnector.py b/mssqlconnector.py deleted file mode 100644 index 8e24eda..0000000 --- a/mssqlconnector.py +++ /dev/null @@ -1,2 +0,0 @@ -## Connector für MSSQL -import dotenv \ No newline at end of file diff --git a/test_odb.py b/test_odb.py new file mode 100644 index 0000000..0392671 --- /dev/null +++ b/test_odb.py @@ -0,0 +1,60 @@ +import adodbapi +import csv +import os + +sdf_file = r"C:\Users\Sebastian Serfling\PycharmProjects\Balzer-WaagenDaten\App.sdf" +output_csv = os.path.join(os.path.dirname(sdf_file), "Weighing_LDB_recovery.csv") + +print(f"📂 Versuche Wiederherstellung aus: {sdf_file}") + +conn_str = ( + "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;" + f"Data Source={sdf_file};Persist Security Info=False;" +) + +try: + conn = adodbapi.connect(conn_str) + cursor = conn.cursor() + print("✅ Verbindung erfolgreich.") + + # Versuche, alle Spaltennamen zu ermitteln + try: + cursor.execute("SELECT * FROM [Weighing_LDB] WHERE 1=0") + columns = [col[0] for col in cursor.description] + print(f"📋 Gefundene Spalten: {columns}") + except Exception as e: + print(f"⚠️ Fehler beim Lesen der Spalten: {e}") + columns = [] + + # Versuch, Spalte für Spalte zu lesen + recovered_rows = [] + error_columns = [] + + for col in columns: + try: + cursor.execute(f"SELECT TOP 5 [{col}] FROM [Weighing_LDB]") + rows = cursor.fetchall() + recovered_rows.append((col, [r[0] for r in rows])) + print(f"✅ Spalte {col}: {len(rows)} Werte gelesen") + except Exception as e: + print(f"❌ Fehler in Spalte {col}: {e}") + error_columns.append(col) + + if recovered_rows: + print(f"\n💾 Schreibe Ergebnis in: {output_csv}") + with open(output_csv, "w", newline="", encoding="utf-8") as f: + writer = csv.writer(f) + writer.writerow(["Spalte", "Beispielwerte"]) + for col, vals in recovered_rows: + writer.writerow([col, str(vals[:5])]) + print("✅ Teildaten erfolgreich exportiert.") + + if error_columns: + print(f"\n⚠️ Problematische Spalten: {error_columns}") + + cursor.close() + conn.close() + print("\n🔚 Wiederherstellung abgeschlossen.") + +except Exception as e: + print(f"❌ Fehler beim Zugriff auf SDF: {e}")