Last active
August 20, 2016 16:55
-
-
Save asayler/d795bd6433fd7086a3f0a6e2c1309f78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import moodle.ws | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print("Missing usernmae argument") | |
sys.exit(1) | |
username = sys.argv[1] | |
host = "https://moodle-test.cs.colorado.edu" | |
courseid = 2 | |
ws = moodle.ws.WS(host) | |
# Another approach to looking up a userid. | |
# For this to work, the WS user must all be a member of the role | |
# assigned the extra "moodle/user:viewalldetails" permission. | |
ws.authenticate("teacher1", | |
"FAKEPASSWORD", | |
"Grading_Serv", | |
error=True) | |
print("Looking up ID for '{}' in course '{}'".format(username, courseid)) | |
options = [('userfields', 'id, username')] | |
res = ws.core_enrol_get_enrolled_users(courseid, options) | |
userid = None | |
for user in res: | |
if user['username'] == username: | |
userid = user['id'] | |
break | |
if userid is None: | |
print("Username '{}' not found".format(username)) | |
sys.exit(1) | |
else: | |
print("ID = '{}'".format(userid)) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment