-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookupstudent.py
executable file
·73 lines (62 loc) · 2.14 KB
/
lookupstudent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# lookupstudent.py - A Quick hack to see what courses a person attends, and
# what education he's registrered on.
# Copyright (c) 2002 Erik Forsberg <[email protected]>
# Released under the GNU GPL
import ldap
import sys
import string
if len(sys.argv) < 2:
print "Usage: %s <studentmailuserid>" % sys.argv[0]
print "Example: %s abcde123" % sys.argv[0]
print
sys.exit(0)
l = ldap.open("ldap.student.liu.se")
l.simple_bind("", "")
r = l.search_st("o=student.liu.se, o=liu.se",
ldap.SCOPE_SUBTREE, "uid=%s" % sys.argv[1])
data = r[0][1]
print "Gecos: %s" % unicode(data["gecos"][0], "utf-8").encode("latin-1")
print
if data.has_key("programcode"):
print "Utbildning:"
print "==========="
filter = '(|'
for utbildning in data["programcode"]:
filter+='(cn='+utbildning+')'
filter+=')'
utbildningar = l.search_st("ou=groups, o=student.liu.se, o=liu.se",
ldap.SCOPE_SUBTREE,
filter,
['cn', 'description'])
for utb in utbildningar:
utbkod = utb[1]['cn'][0]
utbnamn = unicode(utb[1]['description'][0], 'utf8').encode('latin-1')
print "%s" % utbkod + " "*(25-len(utbkod)) + "%s" % utbnamn
else:
print "Ej registrerad på någon utbildning"
print
if data.has_key("coursecode"):
print "Kurskoder:"
print "=========="
filter = '(|'
for kurskod in data["coursecode"]:
filter+='(cn='+kurskod+')'
filter+=')'
kurser = l.search_st("ou=groups, o=student.liu.se, o=liu.se",
ldap.SCOPE_SUBTREE,
filter,
['cn', 'description'])
for kurs in kurser:
kurskod = kurs[1]['cn'][0]
kursnamn = unicode(kurs[1]['description'][0], 'utf8').encode('latin-1')
print "%s" % kurskod + " "*(25-len(kurskod)) + "%s" % kursnamn
else:
print "Ej registrerad på någon kurs"
print
try:
if 0 < len(data["mailforwardingaddress"]):
print "Vidarebefordrar mail till: %s" % data["mailforwardingaddress"][0]
except KeyError:
pass