40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
import os
|
|
from datetime import datetime
|
|
from tkinter import messagebox
|
|
from config import DATEN_DATEI, DATUM_FORMAT
|
|
|
|
def lade_daten():
|
|
vorgaenge = []
|
|
if not os.path.exists(DATEN_DATEI):
|
|
return vorgaenge
|
|
try:
|
|
with open(DATEN_DATEI, "r", encoding="utf-8") as f:
|
|
for zeile in f:
|
|
teile = zeile.strip().split("|")
|
|
if len(teile) >= 3:
|
|
nummer, start_str, stopp_str = teile[:3]
|
|
kommentar = teile[3] if len(teile) > 3 else ""
|
|
start_dt = datetime.strptime(start_str, DATUM_FORMAT)
|
|
stopp_dt = datetime.strptime(stopp_str, DATUM_FORMAT) if stopp_str else None
|
|
vorgaenge.append({
|
|
"nummer": nummer,
|
|
"start": start_dt,
|
|
"stopp": stopp_dt,
|
|
"kommentar": kommentar
|
|
})
|
|
except Exception as e:
|
|
messagebox.showerror("Fehler beim Laden", f"Datei konnte nicht gelesen werden:\n{e}")
|
|
return vorgaenge
|
|
|
|
def speichere_daten(vorgaenge):
|
|
with open(DATEN_DATEI, "w", encoding="utf-8") as f:
|
|
for v in vorgaenge:
|
|
start = v["start"].strftime(DATUM_FORMAT)
|
|
stopp = v["stopp"].strftime(DATUM_FORMAT) if v["stopp"] else ""
|
|
kommentar = v["kommentar"].replace("\n", " ")
|
|
f.write(f"{v['nummer']}|{start}|{stopp}|{kommentar}\n")
|
|
|
|
def reset_daten():
|
|
if os.path.exists(DATEN_DATEI):
|
|
os.remove(DATEN_DATEI)
|