first commit

Erste Version des Programms und erste Testdaten

Signed-off-by: mputzlocher <m.putzlocher@stiftland-gymnasium.de>
master
Martin Putzlocher 2022-01-10 15:03:48 +00:00
parent 487d2e7773
commit 3c1605b480
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Vorname,Nachname,"W-Seminar 1","W-Seminar 2","W-Seminar 3","P-Seminar 1","P-Seminar 2","P-Seminar 3",Klasse
Hans,Dampf,"9 (Katholische Religionslehre)","8 (Informatik)","6 (Geografie)","13 (Musik)","12 (Mathematik)","11 (Latein)",10x
Susi,Quadrat,"12 (Mathematik)","11 (Latein)","13 (Musik)","12 (Mathematik)","10 (Kunst)","11 (Latein)",10x
Ralf,Rechteck,"1 (Biologie)","14 (Physik)","16 (Wirtschaft)","2 (Chemie)","3 (Deutsch)","16 (Wirtschaft)",10x
1 Vorname Nachname W-Seminar 1 W-Seminar 2 W-Seminar 3 P-Seminar 1 P-Seminar 2 P-Seminar 3 Klasse
2 Hans Dampf 9 (Katholische Religionslehre) 8 (Informatik) 6 (Geografie) 13 (Musik) 12 (Mathematik) 11 (Latein) 10x
3 Susi Quadrat 12 (Mathematik) 11 (Latein) 13 (Musik) 12 (Mathematik) 10 (Kunst) 11 (Latein) 10x
4 Ralf Rechteck 1 (Biologie) 14 (Physik) 16 (Wirtschaft) 2 (Chemie) 3 (Deutsch) 16 (Wirtschaft) 10x

92
seminarwahl_cleaner.py Normal file
View File

@ -0,0 +1,92 @@
import re
import tkinter as tk
import tkinter.filedialog as tkfd
import tkinter.messagebox as tkm
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.rowconfigure(0, weight=3)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1)
content = ""
content_lines = list()
newcontent = ""
fname = ""
def load_file(event=None):
global content
global content_lines
global fname
fname = tkfd.askopenfilename(filetypes=(("CSV files","*.csv"),("text files","*.txt")))
try:
f = open(fname, mode='r')
content = f.read()
f.seek(0)
for line in f:
content_lines.append(line)
t_preview.insert(0.0,content)
f.close()
except:
tkm.showerror(title="Fehler beim Öffnen",
message="Öffnen der Datei fehlgeschlagen.")
def clean(event=None):
global content_lines
global newcontent
newcontent = ""
t_preview.delete(0.0,tk.END)
for line in content_lines:
newline = re.sub(r"\s[(][a-zA-Zäöü\s]*[)]", "", line) # Fächer
newline = re.sub(r'["]', "", newline) # Anführungszeichen
tc = re.split(',', newline)
tc = [e.strip() for e in tc]
print(tc)
# Umsortieren
tcnew = [tc[-1]] + [tc[1]] + [tc[0]] + tc[2:-1]
tcnew[-1] = tcnew[-1] + "\n"
newline = ",".join(tcnew)
newcontent += newline
t_preview.insert(0.0,newcontent)
def save_file(event=None):
global fname
global newcontent
if fname == "":
tkm.showerror(title="Fehler beim Speichern",
message="Speichern fehlgeschlagen")
return 1
fname_new = fname[:-4] + "c" + ".csv"
try:
f = open(fname_new, mode='w')
f.write(newcontent)
tkm.showinfo(title="Gespeichert",
message="Datei unter {} gespeichert.".format(fname_new))
except:
tkm.showerror(title="Fehler beim Speichern",
message="Speichern fehlgeschlagen")
bt_choose_file = tk.Button(root, text="Datei auswählen")
bt_choose_file.grid(row=0, column=0)
bt_choose_file["command"] = load_file
bt_clean = tk.Button(root, text="Bereinigen")
bt_clean.grid(row=0, column=1)
bt_clean["command"] = clean
bt_save_file = tk.Button(root, text="Speichern")
bt_save_file.grid(row=0, column=2)
bt_save_file["command"] = save_file
bt_quit = tk.Button(root, text="Beenden", fg="red")
bt_quit.grid(row=0, column=3)
bt_quit["command"] = root.destroy
t_preview = tk.Text(root, height = 10, width = 150)
t_preview.grid(row=1, column=0, columnspan=3, sticky="nwse")
root.mainloop()