Skip to content
Snippets Groups Projects
Commit 9aced993 authored by Hague Matthew UXAC009's avatar Hague Matthew UXAC009
Browse files

Make module-info return intersection of all args

parent 28f2fbce
Branches
No related tags found
No related merge requests found
......@@ -8,8 +8,9 @@ registrations.
* `rhul-student-info.py` -- get student module registrations, email, and
id number. E.g. `python rhul-student-info.py "Matthew" for all
Matthews.
* `rhul-module-info.py` -- get list of students on a module. E.g.
`python rhul-module-info.py CS1811`.
* `rhul-module-info.py` -- get list of students on a module. E.g. `python
rhul-module-info.py CS1811`. Specifying multiple modules gets you the
intersection.
* `rhul-programme-info.py` -- get list of students on a programme. E.g.
`python rhul-programme-info.py Software 2` for all 2nd year students
on a Software Engineering degree.
......
......@@ -14,7 +14,7 @@ LOGIN_RE = re.compile(".*([A-Z]{4}[0-9]{3}).*")
LOGIN_RE_GRP = 1
if len(sys.argv) < 2:
print('Please pass module code.')
print('Please pass at least one module code.')
exit(-1)
search_term = sys.argv[1]
......@@ -29,12 +29,14 @@ BASE='DC=cc,DC=rhul,DC=local'
USERNAME = 'matthew.hague@rhul.ac.uk'
PASS_CMD = [os.path.expanduser('~/.config/mutt/getpass.sh'), 'rhul']
filter = "(&"
for mod_code in sys.argv[1:]:
mod_filter = "(|" + \
"".join(f"{filter.format(mod_code=mod_code)}" for filter in MOD_FILTERS) + \
")"
filter += mod_filter
filter += ")"
if len(sys.argv) < 2:
print('Please pass a search term.')
exit(-1)
mod_code = sys.argv[1]
student_attrs = [
"displayName", "mail",
"extensionAttribute2", "extensionAttribute3", "description"
......@@ -53,17 +55,15 @@ with ldap3.Connection(URI,
authentication=ldap3.SIMPLE) as conn:
count = 0
writer.writerow(["count", "name", "id", "email", "login", "description"])
for filter_fmt in MOD_FILTERS:
mod_filter = filter_fmt.format(mod_code=mod_code)
conn.search(BASE, mod_filter, attributes=student_attrs)
for student in conn.entries:
count += 1
writer.writerow([
count,
student.displayName,
student.extensionAttribute3,
student.mail,
student.extensionAttribute2,
student.description
])
conn.search(BASE, filter, attributes=student_attrs)
for student in conn.entries:
count += 1
writer.writerow([
count,
student.displayName,
student.extensionAttribute3,
student.mail,
student.extensionAttribute2,
student.description
])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment