made a simple member profile thing
authorJacob Parker <j3parker@csclub.uwaterloo.ca>
Thu, 23 Feb 2012 01:58:03 +0000 (20:58 -0500)
committerJacob Parker <j3parker@csclub.uwaterloo.ca>
Thu, 23 Feb 2012 02:03:22 +0000 (21:03 -0500)
bin/member_info.py
bin/members.py

index ae0be9b..72e8274 100755 (executable)
@@ -1,4 +1,38 @@
 #!/usr/bin/python
-import sys, os.path
-print "this is a test!<br>"
-print "got this as an argument: " + os.path.basename(sys.argv[1])
+import sys, os.path, ldap, time
+uid = os.path.basename(sys.argv[1])
+
+cscUri = "http://csclub.uwaterloo.ca/xsltproc"
+cscTerms = ["Winter", "Spring", "Fall"]
+cscShortTerms = ['w', 's', 'f']
+cscLdapUri = "ldap://ldap1.csclub.uwaterloo.ca ldap://ldap2.csclub.uwaterloo.ca"
+cscLdap = None
+cscPeopleBase = 'ou=People,dc=csclub,dc=uwaterloo,dc=ca'
+
+def cscLdapConnect():
+    global cscLdap
+    cscLdap = ldap.initialize(cscLdapUri)
+    cscLdap.simple_bind_s("", "")
+
+cscLdapConnect()
+curDate = time.strftime('%d-%m-%Y')
+members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE,
+          '(&(objectClass=member)(uid=%s))' % uid)
+if len(members) == 0:
+    print "<p>No such user <code>" + uid + "</code></p>"
+    sys.exit()   
+
+(_, user) = members[0]
+
+print "<h1>Profile for " + user['cn'][0] + "</h1>"
+
+print "<p>"
+print "<ul>"
+print "<li>Terms: "
+for t in sorted(user['term']):
+    print t + " "
+print "<br></li>"
+print "<li>Website: <a href=\"http://csclub.uwaterloo.ca/~" + uid + "\">http://csclub.uwaterloo.ca/~" + uid + "</a></li>"
+print "</ul>"
+print "</p>"
+
index 3bc9f2a..7dec816 100755 (executable)
@@ -23,7 +23,7 @@ term = cscShortTerms[int(time.localtime().tm_mon - 1) / 4]
 term2 = cscTerms[int(time.localtime().tm_mon - 1) / 4]
 members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE,
           '(&(objectClass=member)(term=%s%d))' % (term, year))
-members.sort()
+members.sort(key=lambda (_, y): y['cn'][0])
 print "<p>The members for " + term2 + " " + str(year) + " are listed here. We currently have " + str(len(members)) + " members.<br>"
 print "Use of this list for solicitation of any form is prohibited. If you wish to get in touch with the membership as a whole please contact <a href=\"mailto:exec@csclub.uwaterloo.ca\">the Executive</a>.</p>"
 print "<center>"