Last active
August 29, 2015 14:04
-
-
Save gparuthi/d268284d310b75befdd9 to your computer and use it in GitHub Desktop.
Amazon Mturk code for getting things done in python
This file contains hidden or 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
# This code publishes HITS in same batch on Amazon Mechanical Turk | |
import mturk # check out https://github.com/ctrlcctrlv/mturk-python | |
conf = { | |
"use_sandbox" : True, | |
"stdout_log" : False, | |
"verify_mturk_ssl" : True, | |
"aws_key" : "your_key", | |
"aws_secret_key" : "your_secret" | |
} | |
m = mturk.MechanicalTurk(conf) | |
r = m.request("GetAccountBalance") | |
if r.valid: | |
print r.get_response_element("AvailableBalance") | |
# generate HITTypeId which is basically the batch id | |
title = 'Help someone to walk more in their daily routine.' | |
description = 'Fix a message that helps support someone to walk more' | |
keywords = 'idea, message, text, walking, support, help, physical, activity' | |
reward = {'Amount':0.10, 'CurrencyCode':'USD'} | |
duration= 60*10 | |
autoapp = 60*60*48 | |
r = m.request("RegisterHITType",{'Title':title, 'Description' :description, 'Keywords':keywords, | |
'Reward':reward, 'AssignmentDurationInSeconds':duration, 'AutoApprovalDelayInSeconds': autoapp | |
}) | |
hit_type_id = r['RegisterHITTypeResponse']['RegisterHITTypeResult']['HITTypeId'] | |
# get HITTypeId from the result and replace XXX with that below | |
hit_type_id = 'XXX' | |
lifetime = 60*60*24 | |
layout_id = 'YYY' # this is the layout id | |
# now create HITs with the HITTypeId as received | |
r = m.request("CreateHIT",{'HITTypeId':hit_type_id, 'LifetimeInSeconds': lifetime, | |
'HITLayoutId': layout_id, | |
'HITLayoutParameter':[{'Name':'message', 'Value':'1m'},{'Name':'situation', 'Value':'1s'}], | |
}) | |
r = m.request("CreateHIT",{'HITTypeId':hit_type_id, 'LifetimeInSeconds': lifetime, | |
'HITLayoutId': layout_id, | |
'HITLayoutParameter':[{'Name':'message', 'Value':'1m'},{'Name':'situation', 'Value':'1s'}], | |
}) | |
r = m.request("CreateHIT",{'HITTypeId':hit_type_id, 'LifetimeInSeconds': lifetime, | |
'HITLayoutId': layout_id, | |
'HITLayoutParameter':[{'Name':'message', 'Value':'1m'},{'Name':'situation', 'Value':'1s'}], | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone needs more help, I would be happy to make this more detailed