-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmturk.py
119 lines (94 loc) · 3 KB
/
mturk.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import boto3,os,argparse
import pprint # just to make the output more readable; feel free to leave it out in your code
warning=" Use of this flag is strongly discouraged."
# let's add some arguments
parser=argparse.ArgumentParser(prog="AMT Launch Code")
parser.add_argument(
'-t','--taskURL',
help="the task URL in the following form 'https://foobar.com/task.html'"
)
parser.add_argument(
'--live',
action="store_true",
help="Send the task to the real AMT marketplace.",
)
parser.add_argument(
'--awsKey',
help="Preferred AWS Key.{}".format(warning)
)
parser.add_argument(
'--title',
help="A custom title for the HIT (used in conjunction with the `create` flag)."
)
parser.add_argument(
'--awsSecret',
help="Your AWS Secret.{}".format(warning)
)
parser.add_argument(
'-c',
'--create',
action="store_true",
help="Create a *new* HIT."
)
parser.add_argument(
'-l',
'--listHITs',
action="store_true",
help="List extant HITs."
)
parser.add_argument(
'-e',
'--extend',
help="Extend a HIT that's already in the marketplace."
)
parser.add_argument(
'-g',
'--getHIT',
help="Get information about a specific HIT; needs a HIT ID."
)
args=parser.parse_args()
endpoint={
'production': 'https://mturk-requester.us-east-1.amazonaws.com',
'sandbox': 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'
}
awsXMLSchema="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd"
external_content ="""
<ExternalQuestion xmlns="{awsXMLSchema}">
<ExternalURL>{taskURL}</ExternalURL>
<FrameHeight>400</FrameHeight>
</ExternalQuestion>
""".format(awsXMLSchema=awsXMLSchema,taskURL=args.taskURL)
quals=[
{
'QualificationTypeId': "000000000000000000L0", # Amazon has a lot of arcane looking qualification types
"Comparator": "GreaterThan",
"IntegerValues": [85]
}
]
client=boto3.client(
service_name='mturk',
region_name='us-east-1',
aws_access_key_id=args.awsKey or os.environ['AMT_key'], # => ~/.envariables
aws_secret_access_key=args.awsSecret or os.environ['AMT_secret'], # => ~/.envariables
endpoint_url = endpoint['production'] if args.live else endpoint['sandbox']
)
if args.listHITs:
response=client.list_hits()
pprint.pprint(response)
if args.getHIT:
response=client.get_hit(
HITId=args.getHIT)
pprint.pprint(response)
if args.create:
response = client.create_hit(
MaxAssignments = 9,
LifetimeInSeconds = 60*60, # the HIT will only be active for 1 hour.
AssignmentDurationInSeconds = (60*30), # this gives workers 30 minutes to complete it once they claim it.
Reward ='0.50', # calculate the appropriate rate so people are getting paid fairly for their time.
# if this task took 30 minutes to complete and i was paying $0.50, workers wouldn't even bother to do.
Title = args.title or "some generic task, probably created accidentally",
Keywords = 'question, answer, research, etc',
Description = 'Answer a few survey questions',
QualificationRequirements=quals,
Question = external_content,
)