Merge branch 'master' of ../www.fuck
[public/www-new.git] / bin / members.py
1 #!/usr/bin/python
2 import ldap, time, operator
3
4 #
5 # globals
6 #
7 cscUri = "http://csclub.uwaterloo.ca/xsltproc"
8 cscTerms = ["Winter", "Spring", "Fall"]
9 cscShortTerms = ['w', 's', 'f']
10 cscLdapUri = "ldap://ldap1.csclub.uwaterloo.ca ldap://ldap2.csclub.uwaterloo.ca"
11 cscLdap = None
12 cscPeopleBase = 'ou=People,dc=csclub,dc=uwaterloo,dc=ca'
13
14 def cscLdapConnect():
15     global cscLdap
16     cscLdap = ldap.initialize(cscLdapUri)
17     cscLdap.simple_bind_s("", "")
18
19 cscLdapConnect()
20 curDate = time.strftime('%d-%m-%Y')
21 year = time.localtime().tm_year
22 term = cscShortTerms[int(time.localtime().tm_mon - 1) / 4]
23 term2 = cscTerms[int(time.localtime().tm_mon - 1) / 4]
24 members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE,
25           '(&(objectClass=member)(term=%s%d))' % (term, year))
26 members.sort(key=lambda (_, y): y['cn'][0])
27 print "<h1>Members This Term</h1>"
28 print "<p>The members for " + term2 + " " + str(year) + " are listed here. We currently have " + str(len(members)) + " members.<br>"
29 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>"
30 print "<center>"
31 print "<table>"
32 print "    <tr><td>Name</td><td>Program</td><td>Username</td>"
33 for (_, member) in members:
34     if not 'program' in member:
35         member['program'] = ['']
36     print "    <tr>"
37     print "        <td><a href=\"http://csclub.uwaterloo.ca/~j3parker/pub/csc/About/Members/" + member['uid'][0] + "\">" + member['cn'][0] + "</a></td>"
38     print "        <td>" + member['program'][0] + "</td>"
39     print "        <td>" + member['uid'][0] + "</td>"
40     print "    </tr>"
41 print "</table>"
42 print "</center>"