Erster Commit
This commit is contained in:
parent
117d30e782
commit
7a13310703
3 changed files with 141 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
# Datendateien ignorieren
|
||||||
|
*.csv
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
30
README.md
30
README.md
|
@ -1,3 +1,33 @@
|
||||||
# IServ2LMS
|
# IServ2LMS
|
||||||
|
|
||||||
Skripte für die Anbindung von Moodle/LogineoLMS an IServ.
|
Skripte für die Anbindung von Moodle/LogineoLMS an IServ.
|
||||||
|
|
||||||
|
## Vorbereitung
|
||||||
|
|
||||||
|
1. Gruppen exportieren (Gruppenliste in IServ erstellen)
|
||||||
|
2. Kollegiumsgruppe als Export_Kollegium.csv ablegen
|
||||||
|
3. SuS-Gruppe als Export_SuS.csv ablegen
|
||||||
|
|
||||||
|
## Sonstiges
|
||||||
|
### Aufbau des Exports
|
||||||
|
IServ exportiert CSV mit folgenden Einstellungen:
|
||||||
|
- Codierung: UTF-8 mit BOM
|
||||||
|
- Zeilenumbruch: LF
|
||||||
|
- Spaltentrenner: ;
|
||||||
|
- Strings: ""
|
||||||
|
|
||||||
|
### Feldzuordnung
|
||||||
|
Moodle | IServ | Kommentar
|
||||||
|
---|---|---
|
||||||
|
username | IServ-Username
|
||||||
|
firstname | Vorname
|
||||||
|
lastname | Nachname
|
||||||
|
email | IServ-Mailadresse | i.d.R. username@iserv-instanz
|
||||||
|
profile_field_Klasse | Klasse (oder Kollegium) | hieraus wird die globale Gruppe
|
||||||
|
profile_field_Lehrer_in | 0 oder 1 | für Lehrer*innen 1
|
||||||
|
idnumber | Import-ID | nicht notwendig, oft leer
|
||||||
|
password | oauth2 | WICHTIG, sonst kein Login möglichMoodle | IServ | Kommentar
|
||||||
|
course1..X | Gruppen | In Moodle eine Spalte je Kurs, in IServ kommasepariert in einer Spalte
|
||||||
|
role1..X | n.V. | Rolle im Kurs, i.d.R. *editingteacher* oder *student*
|
||||||
|
sysrole1..X | n.V. | Rolle im System evtl. sinvoll für Lehrkräfte: *coursecreator*
|
||||||
|
|
||||||
|
|
107
convert.py
Executable file
107
convert.py
Executable file
|
@ -0,0 +1,107 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# Konvertiere IServ-Gruppenlisten in Moodle-Importdateien
|
||||||
|
# 2022 by Daniel Spittank, daniel.spittank@gymsedan.de
|
||||||
|
# Lizenz: GPLv3
|
||||||
|
|
||||||
|
# Importe
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
import csv
|
||||||
|
|
||||||
|
# Schuljahr
|
||||||
|
schuljahr='22'
|
||||||
|
|
||||||
|
# Ergebnisspeicher
|
||||||
|
members = []
|
||||||
|
maxgroups = 0
|
||||||
|
|
||||||
|
# Kollegium einlesen
|
||||||
|
with open('Export_Kollegium.csv', 'r', encoding='utf-8-sig') as f:
|
||||||
|
# CSV einlesen
|
||||||
|
cr = csv.DictReader(f, delimiter=';', lineterminator='\n')
|
||||||
|
|
||||||
|
for row in cr:
|
||||||
|
# Person erstellen
|
||||||
|
p = {
|
||||||
|
'firstname' : row['Vorname'],
|
||||||
|
'lastname' : row['Nachname'],
|
||||||
|
'username' : row['Account'],
|
||||||
|
'email' : row['E-Mail-Adresse'],
|
||||||
|
'profile_field_Klasse' : 'Kollegium',
|
||||||
|
'profile_field_Lehrer_in' : '1',
|
||||||
|
'idnumber' : row['Klasse/Information'], #row['Import-ID']
|
||||||
|
'password': 'oauth2'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Gruppen der Person laden
|
||||||
|
gt = row['Alle Gruppen'].split(',')
|
||||||
|
|
||||||
|
# Gruppen filtern
|
||||||
|
gruppen = list(filter(lambda g: g.startswith('Kurs') or g.startswith('Klasse'), gt))
|
||||||
|
|
||||||
|
# Gruppen ins Format von Moodle bringen
|
||||||
|
for i, g in enumerate(gruppen):
|
||||||
|
p['course' + str(i+1)] = schuljahr + '_' + g
|
||||||
|
p['role' + str(i+1)] = 'editingteacher'
|
||||||
|
|
||||||
|
maxgroups = max(maxgroups, len(gruppen))
|
||||||
|
# Person zur Liste hinzfügen
|
||||||
|
members.append(p)
|
||||||
|
|
||||||
|
# SuS einlesen
|
||||||
|
with open('Export_SuS.csv', 'r', encoding='utf-8-sig') as f:
|
||||||
|
# CSV einlesen
|
||||||
|
cr = csv.DictReader(f, delimiter=';', lineterminator='\n')
|
||||||
|
|
||||||
|
for row in cr:
|
||||||
|
# Person erstellen
|
||||||
|
p = {
|
||||||
|
'firstname' : row['Vorname'],
|
||||||
|
'lastname' : row['Nachname'],
|
||||||
|
'username' : row['Account'],
|
||||||
|
'email' : row['E-Mail-Adresse'],
|
||||||
|
'profile_field_Klasse' : row['Klasse/Information'],
|
||||||
|
'profile_field_Lehrer_in' : '0',
|
||||||
|
'idnumber' : row['Import-ID'],
|
||||||
|
'password': 'oauth2'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Gruppen der Person laden
|
||||||
|
gt = row['Alle Gruppen'].split(',')
|
||||||
|
|
||||||
|
# Gruppen filtern
|
||||||
|
gruppen = list(filter(lambda g: g.startswith('Kurs') or g.startswith('Klasse'), gt))
|
||||||
|
|
||||||
|
# Gruppen ins Format von Moodle bringen
|
||||||
|
for i, g in enumerate(gruppen):
|
||||||
|
p['course' + str(i+1)] = schuljahr + '_' + g
|
||||||
|
p['role' + str(i+1)] = 'student'
|
||||||
|
|
||||||
|
maxgroups = max(maxgroups, len(gruppen))
|
||||||
|
# Person zur Liste hinzfügen
|
||||||
|
members.append(p)
|
||||||
|
|
||||||
|
# Moodle-Importdatei schreiben
|
||||||
|
with open('import.csv', 'w', encoding='utf-8-sig') as f:
|
||||||
|
# CSV DictWriter anlegen
|
||||||
|
fieldnames = [
|
||||||
|
'username',
|
||||||
|
'firstname',
|
||||||
|
'lastname',
|
||||||
|
'email',
|
||||||
|
'profile_field_Klasse',
|
||||||
|
'profile_field_Lehrer_in',
|
||||||
|
'idnumber',
|
||||||
|
'password']
|
||||||
|
|
||||||
|
for i in range(1,maxgroups+1):
|
||||||
|
fieldnames.append("course" + str(i))
|
||||||
|
fieldnames.append("role" + str(i))
|
||||||
|
|
||||||
|
cw = csv.DictWriter(f, delimiter=';', fieldnames=fieldnames)
|
||||||
|
|
||||||
|
# Datei schreiben
|
||||||
|
cw.writeheader()
|
||||||
|
for p in members:
|
||||||
|
cw.writerow(p)
|
Loading…
Reference in a new issue