Last active
August 20, 2016 16:53
-
-
Save asayler/2fa0c061d220b8520b276112a370dce4 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" | |
ws = moodle.ws.WS(host) | |
# Must authenticate as Moodle admin in order to access full user list | |
# Note: you can work around this restriction by adding the | |
# "moodle/user:viewalldetails" permission to whichever role you | |
# want to use this function, e.g. 'teacher'. | |
ws.authenticate("admin", | |
"FAKEPASSWORD", | |
"Grading_Serv", | |
error=True) | |
print("Looking up ID for '{}'".format(username)) | |
res = ws.core_user_get_users([('username', username)]) | |
user_list = res['users'] | |
if len(user_list) < 1: | |
print("Username not found") | |
sys.exit(1) | |
elif len(user_list) > 1: | |
print("Multiple users found") | |
sys.exit(1) | |
user = user_list[0] | |
user_id = user['id'] | |
print("ID = '{}'".format(user_id)) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment