Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS_ACCESS_KEY_ID = "YOUR KEY ID HERE"
AWS_SECRET_ACCESS_KEY = "YOUR SECRET KEY HERE"
USE_SANDBOX = False
import config
from boto.mturk.connection import MTurkConnection
from boto.mturk.question import ExternalQuestion
from boto.mturk.qualification import (Qualifications,
PercentAssignmentsApprovedRequirement,
NumberHitsApprovedRequirement, LocaleRequirement)
from boto.mturk.price import Price
import datetime
# ============================HELPER METHODS=======================
# Quick method to encode url parameters
def encode_get_parameters(baseurl, arg_dict):
queryString = baseurl + "?"
for indx, key in enumerate(arg_dict):
queryString += str(key) + "=" + str(arg_dict[key])
if indx < len(arg_dict)-1:
queryString += "&"
return queryString
# ============================VARIABLES============================
# START AWS CONFIGURATION VARS
AWS_ACCESS_KEY_ID = config.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY = config.AWS_SECRET_ACCESS_KEY
# END MAIN CONFIGURATION VARS
# START IMPORTANT HIT VARIABLES
sandbox = config.USE_SANDBOX
base_url = "https://firefoxmetzger.github.io/robot_capabilities_glue/"
params_to_encode = {}
assignments_per_hit = 25
payment_per_assignment = 0.8
# END IMPORTANT HIT VARIABLES
# START QUALIFICATION CONFIGURATION
qualifications = Qualifications()
qual_1 = PercentAssignmentsApprovedRequirement(
comparator="GreaterThan",
integer_value="95")
qualifications.add(qual_1)
qual_2 = NumberHitsApprovedRequirement(
comparator="GreaterThan",
integer_value="100")
qualifications.add(qual_2)
qual_3 = LocaleRequirement(
comparator="In",
locale=["US", "GB", "CA", "AU", "NZ"])
qualifications.add(qual_3)
# END QUALIFICATION CONFIGURATION
# START DECORATIVE HIT VARIABLES
hit_title = "Evaluate Robot Capabilities! (6 minutes / $0.8 USD)"
hit_description = "Rate a robot on a number of capabilities in a short survey (approximately 6 minutes)"
hit_keywords = ["university study", "robot", "survey", "short", "quick"]
duration_in_seconds = 20*60
frame_height = 1200
# END DECORATIVE HIT VARIABLES
# =================================================================
# Initialize boto connection based on sandbox.
if sandbox:
AMAZON_HOST = "mechanicalturk.sandbox.amazonaws.com"
else:
AMAZON_HOST = "mechanicalturk.amazonaws.com"
connection = MTurkConnection(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
host=AMAZON_HOST)
# Selecting which endpoint to pass as parameter
if sandbox:
external_submit_endpoint = "https://workersandbox.mturk.com/mturk/externalSubmit"
else:
external_submit_endpoint = "https://www.mturk.com/mturk/externalSubmit"
#params_to_encode['host'] = external_submit_endpoint
encoded_url = encode_get_parameters(base_url, params_to_encode)
create_hit_result = connection.create_hit(
title=hit_title,
description=hit_description,
keywords=hit_keywords,
duration=duration_in_seconds,
lifetime=datetime.timedelta(days=8),
max_assignments=assignments_per_hit,
question=ExternalQuestion(encoded_url, frame_height),
reward=Price(amount=payment_per_assignment),
# Determines information returned by certain API methods.
response_groups=('Minimal', 'HITDetail'),
qualifications=qualifications)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment