WeBWorK Main Forum

Possible to add a new user on command line to a course?

Re: Possible to add a new user on command line to a course?

by Christian Seberino -
Number of replies: 0
Here is a script that does the trick.  You need Python and a Python package called "mechanize" to run it.  Just replace the URL and password below.

#!/usr/bin/env python

import mechanize
import sys

if len(sys.argv) != 5:
        print "Usage: ./add_student <first name> <last name> <username> <course>"

BASE_URL  = "<Put your Webwork server URL here.>"
WW_PASSWD = "<Put your Webwork server admin password here"
ADD_URL   = BASE_URL + "/%s/instructor/add_users/?number_of_students=1"

first_name = sys.argv[1]
last_name  = sys.argv[2]
username   = sys.argv[3]
course     = sys.argv[4].replace(" ", "_")

def authenticate(class_, password):
        browser = mechanize.Browser()
        browser.open(BASE_URL + "/" + class_)
        browser.select_form(nr = 0)
        browser["user"] = "admin"
        browser["passwd"] = password

        return browser

add_url = BASE_URL + "/%s/instructor/add_users/?number_of_students=1" % course
browser = authenticate(course, WW_PASSWD)

browser["last_name_1"]   = last_name
browser["first_name_1"]  = first_name
browser["student_id_1"]  = username
browser["new_user_id_1"] = username