made a simple member profile thing

This commit is contained in:
Jacob Parker 2012-02-22 20:58:03 -05:00
parent 075fc075c2
commit c49e0d942a
2 changed files with 38 additions and 4 deletions

View File

@ -1,4 +1,38 @@
#!/usr/bin/python #!/usr/bin/python
import sys, os.path import sys, os.path, ldap, time
print "this is a test!<br>" uid = os.path.basename(sys.argv[1])
print "got this as an argument: " + 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>"

View File

@ -23,7 +23,7 @@ term = cscShortTerms[int(time.localtime().tm_mon - 1) / 4]
term2 = cscTerms[int(time.localtime().tm_mon - 1) / 4] term2 = cscTerms[int(time.localtime().tm_mon - 1) / 4]
members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE, members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE,
'(&(objectClass=member)(term=%s%d))' % (term, year)) '(&(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 "<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 "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>" print "<center>"