-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddUser.py
More file actions
40 lines (28 loc) · 896 Bytes
/
addUser.py
File metadata and controls
40 lines (28 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import mechanize, re, sys
if (len(sys.argv) != 3):
print "python addUser.py fname lname"
sys.exit(1)
br = mechanize.Browser()
br.open("http://localhost")
br.form = list(br.forms())[0]
br.form['user[email]']="faimsadmin@intersect.org.au"
br.form['user[password]']="Pass.123"
br.submit()
todo=[]
for link in br.links():
moduleMatch = re.compile("/project_modules/[0-9]+").search(link.url)
if moduleMatch:
todo.append(link)
for link in todo:
#print link
br.follow_link(link)
br.follow_link(br.find_link(url_regex=re.compile(".*edit_project_module_user")))
br.form = list(br.forms())[0]
control=br.form.find_control("user_id")
#print control.items
for item in control.items:
userMatch = re.compile(sys.argv[1]+" "+sys.argv[2]).search(str([label.text for label in item.get_labels()]))
if userMatch:
control.value = [item.name]
print control.value
br.submit()