From 2a4598815605611b5d3cbb75e5cf90f2d27f3314 Mon Sep 17 00:00:00 2001 From: Daniel Spittank Date: Sun, 22 Jan 2023 20:20:31 +0100 Subject: [PATCH] =?UTF-8?q?Kursliste=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convert.py | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/convert.py b/convert.py index d1204db..a01bb9f 100755 --- a/convert.py +++ b/convert.py @@ -11,10 +11,12 @@ import csv # Schuljahr schuljahr='22' +categoryid='17' # Ergebnisspeicher members = [] -maxgroups = 0 +maxkurse = 0 +allekurse = [] # Kollegium einlesen with open('Export_Kollegium.csv', 'r', encoding='utf-8-sig') as f: @@ -38,14 +40,20 @@ with open('Export_Kollegium.csv', 'r', encoding='utf-8-sig') as f: gt = row['Alle Gruppen'].split(',') # Gruppen filtern - gruppen = list(filter(lambda g: g.startswith('Kurs') or g.startswith('Klasse'), gt)) + gruppen = list(filter(lambda g: g.startswith('Kurs_') or g.startswith('Klasse_'), gt)) - # Gruppen ins Format von Moodle bringen + # Gruppen ins Format von Moodle bringen und Gruppen sammeln for i, g in enumerate(gruppen): p['course' + str(i+1)] = schuljahr + '_' + g p['role' + str(i+1)] = 'editingteacher' - maxgroups = max(maxgroups, len(gruppen)) + # Kurse sammeln + if g not in allekurse: + allekurse.append(g) + + # Anzahl der maximalen Gruppen pro Person merken + maxkurse = max(maxkurse, len(gruppen)) + # Person zur Liste hinzfügen members.append(p) @@ -71,19 +79,24 @@ with open('Export_SuS.csv', 'r', encoding='utf-8-sig') as f: gt = row['Alle Gruppen'].split(',') # Gruppen filtern - gruppen = list(filter(lambda g: g.startswith('Kurs') or g.startswith('Klasse'), gt)) + gruppen = list(filter(lambda g: g.startswith('Kurs_') or g.startswith('Klasse_'), gt)) - # Gruppen ins Format von Moodle bringen + # Gruppen ins Format von Moodle bringen und Gruppen sammeln for i, g in enumerate(gruppen): p['course' + str(i+1)] = schuljahr + '_' + g p['role' + str(i+1)] = 'student' - maxgroups = max(maxgroups, len(gruppen)) + # Kurse sammeln + if g not in allekurse: + allekurse.append(g) + + maxkurse = max(maxkurse, len(gruppen)) + # Person zur Liste hinzfügen members.append(p) -# Moodle-Importdatei schreiben -with open('import.csv', 'w', encoding='utf-8-sig') as f: +# Moodle-Importdatei für User schreiben +with open('Import_Users.csv', 'w', encoding='utf-8-sig') as f: # CSV DictWriter anlegen fieldnames = [ 'username', @@ -95,7 +108,7 @@ with open('import.csv', 'w', encoding='utf-8-sig') as f: 'idnumber', 'password'] - for i in range(1,maxgroups+1): + for i in range(1,maxkurse+1): fieldnames.append("course" + str(i)) fieldnames.append("role" + str(i)) @@ -105,3 +118,24 @@ with open('import.csv', 'w', encoding='utf-8-sig') as f: cw.writeheader() for p in members: cw.writerow(p) + +# Moodle-Importdatei für Kurse schreiben +with open('Import_Courses.csv', 'w', encoding='utf-8-sig') as f: + # CSV DictWriter anlegen + fieldnames = [ + 'shortname', + 'fullname', + 'category', + 'visible'] + + cw = csv.DictWriter(f, delimiter=';', fieldnames=fieldnames) + + # Datei schreiben + cw.writeheader() + for c in allekurse: + cw.writerow({ + 'shortname' : schuljahr + '_' + c, + 'fullname' : schuljahr + '_' + c, + 'category' : categoryid, + 'visible' : '1' + })