Skip to content

Instantly share code, notes, and snippets.

@trcook
Last active August 29, 2015 14:24
Show Gist options
  • Save trcook/263003d9305045b7c073 to your computer and use it in GitHub Desktop.
Save trcook/263003d9305045b7c073 to your computer and use it in GitHub Desktop.
auto assign mturk qualifications from a hit using boto
from boto import *
mturk=connect_mturk()
x=mturk.get_all_hits()
m=list(x)
b=m
m=list(x)
while m:
b.append(m)
print(m)
m=list(x)
# set this to the appropriate hitid that you want to grant quals to
def updateid(hitid):
assignments=mturk.get_assignments(hitid ,page_size=30,page_number=1)
i=1
workers=[a.WorkerId for a in assignments]
while assignments:
i=i+1
assignments=mturk.get_assignments(hitid ,page_size=1,page_number=i)
workers.extend([a.WorkerId for a in assignments])
# replace 'prior survey' with a name that ***UNIQUELY*** identifies your qualification
qualid=mturk.search_qualification_types('prior survey')[0].QualificationTypeId
for i in workers:
try:
mturk.assign_qualification(qualid, i, value=1, send_notification=False)
except:
mturk.update_qualification_score(qualid, i, value=1)
# To run on all hits:
#for i in b:
# hitid=i.HITId
# updateid(hitid)
# to search for a specific hit:
# ["%s -- %s -- %s -- %s " % (i,x.Title,x.CreationTime,x.NumberOfAssignmentsAvailable) for i,x in enumerate(b)]
# Then, for whatever number in the list:
#updateid(b[0].HITId)
# use this to make sure that your search string will uniquely identify the correct qualification (you could use this to manually get the qualification id and put it in the updateid method above:
# print ["%(name)s %(id)s" % {"name":x.Name,"id":x.QualificationTypeId} for x in mturk.search_qualification_types('prior')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment