mirror of
https://git.schule.click/GymSedan/IServ2LMS.git
synced 2024-12-22 16:05:14 +01:00
Kursliste hinzugefügt
This commit is contained in:
parent
7a13310703
commit
2a45988156
1 changed files with 44 additions and 10 deletions
54
convert.py
54
convert.py
|
@ -11,10 +11,12 @@ import csv
|
||||||
|
|
||||||
# Schuljahr
|
# Schuljahr
|
||||||
schuljahr='22'
|
schuljahr='22'
|
||||||
|
categoryid='17'
|
||||||
|
|
||||||
# Ergebnisspeicher
|
# Ergebnisspeicher
|
||||||
members = []
|
members = []
|
||||||
maxgroups = 0
|
maxkurse = 0
|
||||||
|
allekurse = []
|
||||||
|
|
||||||
# Kollegium einlesen
|
# Kollegium einlesen
|
||||||
with open('Export_Kollegium.csv', 'r', encoding='utf-8-sig') as f:
|
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(',')
|
gt = row['Alle Gruppen'].split(',')
|
||||||
|
|
||||||
# Gruppen filtern
|
# 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):
|
for i, g in enumerate(gruppen):
|
||||||
p['course' + str(i+1)] = schuljahr + '_' + g
|
p['course' + str(i+1)] = schuljahr + '_' + g
|
||||||
p['role' + str(i+1)] = 'editingteacher'
|
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
|
# Person zur Liste hinzfügen
|
||||||
members.append(p)
|
members.append(p)
|
||||||
|
|
||||||
|
@ -71,19 +79,24 @@ with open('Export_SuS.csv', 'r', encoding='utf-8-sig') as f:
|
||||||
gt = row['Alle Gruppen'].split(',')
|
gt = row['Alle Gruppen'].split(',')
|
||||||
|
|
||||||
# Gruppen filtern
|
# 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):
|
for i, g in enumerate(gruppen):
|
||||||
p['course' + str(i+1)] = schuljahr + '_' + g
|
p['course' + str(i+1)] = schuljahr + '_' + g
|
||||||
p['role' + str(i+1)] = 'student'
|
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
|
# Person zur Liste hinzfügen
|
||||||
members.append(p)
|
members.append(p)
|
||||||
|
|
||||||
# Moodle-Importdatei schreiben
|
# Moodle-Importdatei für User schreiben
|
||||||
with open('import.csv', 'w', encoding='utf-8-sig') as f:
|
with open('Import_Users.csv', 'w', encoding='utf-8-sig') as f:
|
||||||
# CSV DictWriter anlegen
|
# CSV DictWriter anlegen
|
||||||
fieldnames = [
|
fieldnames = [
|
||||||
'username',
|
'username',
|
||||||
|
@ -95,7 +108,7 @@ with open('import.csv', 'w', encoding='utf-8-sig') as f:
|
||||||
'idnumber',
|
'idnumber',
|
||||||
'password']
|
'password']
|
||||||
|
|
||||||
for i in range(1,maxgroups+1):
|
for i in range(1,maxkurse+1):
|
||||||
fieldnames.append("course" + str(i))
|
fieldnames.append("course" + str(i))
|
||||||
fieldnames.append("role" + str(i))
|
fieldnames.append("role" + str(i))
|
||||||
|
|
||||||
|
@ -105,3 +118,24 @@ with open('import.csv', 'w', encoding='utf-8-sig') as f:
|
||||||
cw.writeheader()
|
cw.writeheader()
|
||||||
for p in members:
|
for p in members:
|
||||||
cw.writerow(p)
|
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'
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue