Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Super simple python script that uses boto to connect to amazon mturk. If you use the sandbox, you'll see a balance of $10,000! Otherwise, you'll see your normal balance.
import boto.mturk.connection
sandbox_host = 'mechanicalturk.sandbox.amazonaws.com'
real_host = 'mechanicalturk.amazonaws.com'
mturk = boto.mturk.connection.MTurkConnection(
aws_access_key_id = 'XXX',
aws_secret_access_key = 'XXX',
host = sandbox_host,
debug = 1 # debug = 2 prints out all requests. but we'll just keep it at 1
)
print boto.Version
print mturk.get_account_balance()
import boto.mturk.connection
import boto.mturk.question
sandbox_host = 'mechanicalturk.sandbox.amazonaws.com'
real_host = 'mechanicalturk.amazonaws.com'
mturk = boto.mturk.connection.MTurkConnection(
aws_access_key_id = 'XXX',
aws_secret_access_key = 'XXX',
host = sandbox_host,
debug = 1 # debug = 2 prints out all requests. but we'll just keep it at 1
)
print boto.Version
print mturk.get_account_balance()
URL = "https://the-url-of-my-external-hit"
title = "A special hit!"
description = "The more verbose description of the job!"
keywords = ["cats", "dogs", "rabbits"]
frame_height = 500 # the height of the iframe holding the external hit
amount = .05
questionform = boto.mturk.question.ExternalQuestion( URL, frame_height )
create_hit_result = mturk.create_hit(
title = title,
description = description,
keywords = keywords,
question = questionform,
reward = boto.mturk.price.Price( amount = amount),
response_groups = ( 'Minimal', 'HITDetail' ), # I don't know what response groups are
)
HIT = create_hit_result[0]
assert create_hit_result.status
print '[create_hit( %s, $%s ): %s]' % ( URL, amount, HIT.HITId )
<!-- This is a django page so turk_submit_url is a variable I made in my view that got turkSubmitTo from the GET request. Also, the hidden user_id input gets updated with some javascript when the page loads and the task starts up. -->
<h4>Thanks for working on this task!</h4>
<form id="mturk_form" method="post" action="{{turk_submit_url}}/externalSubmit">
<input type="hidden" name="user_id" id="user_id" />
<input type="hidden" name="assignmentId" value="{{assignmentId}}" />
<textarea name="feedback" rows=10 cols=60 placeholder="Enter any feedback you have about the task here"></textarea>
<br /><br />
<button class="btn btn-success" type="submit" value="Submit">Finish and Submit HIT</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment