Пример #1
0
from boto.mturk.price import Price
from boto.mturk.question import HTMLQuestion
from boto.mturk.connection import MTurkRequestError

import os
import simpleamt
import sys

if __name__ == '__main__':
  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])
  parser.add_argument('--hit_properties_file', type=argparse.FileType('r'))
  parser.add_argument('--html_template')
  parser.add_argument('--input_json_file', type=argparse.FileType('r'))
  args = parser.parse_args()

  mtc = simpleamt.get_mturk_connection_from_args(args)

  hit_properties = json.load(args.hit_properties_file)
  hit_properties['reward'] = Price(hit_properties['reward'])
  simpleamt.setup_qualifications(hit_properties, mtc)

  frame_height = hit_properties.pop('frame_height')
  env = simpleamt.get_jinja_env(args.config)
  template = env.get_template(args.html_template)

  if args.hit_ids_file is None:
    print('Need to input a hit_ids_file')
    sys.exit()
  if os.path.isfile(args.hit_ids_file):
    print('hit_ids_file already exists')
    sys.exit()
Пример #2
0
import argparse

import simpleamt

if __name__ == '__main__':
    parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()],
                                     description="Delete HITs")
    parser.add_argument('--hit_id')
    args = parser.parse_args()
    mtc = simpleamt.get_mturk_connection_from_args(args)
    hit_id = args.hit_id

    print('This will delete HIT with ID: %s with sandbox=%s' %
          (hit_id, str(args.sandbox)))
    print 'Continue?'
    s = raw_input('(Y/N): ')
    if s == 'Y' or s == 'y':
        try:
            mtc.disable_hit(hit_id)
        except:
            print 'Failed to disable: %s' % (hit_id)
    else:
        print 'Aborting'
Пример #3
0
import argparse, json, sys
import simpleamt
def process_assignments(mtc, hit_id):  results = []  assignments = mtc.get_assignments(hit_id) for a in assignments: if a.AssignmentStatus in ['Approved', 'Submitted']: try:        output = json.loads(a.answers[0][0].fields[0]) except ValueError as e: print >> sys.stderr, ('Bad data from assignment %s (worker %s)' % (a.AssignmentId, a.WorkerId)) continue      results.append({ 'assignment_id': a.AssignmentId, 'hit_id': hit_id, 'worker_id': a.WorkerId, 'output': json.loads(a.answers[0][0].fields[0]),      }) return results
if __name__ == '__main__':  parser = argparse.ArgumentParser(parents=[simpleamt.get_parent_parser()])  args = parser.parse_args()  mtc = simpleamt.get_mturk_connection_from_args(args)   results = []
 if args.hit_ids_file is None: for hit in mtc.get_all_hits():      results += process_assignments(mtc, hit.HITId) else: with open(args.hit_ids_file, 'r') as f: for line in f:        hit_id = line.strip()        results += process_assignments(mtc, hit_id)
 for assignment_result in results: print json.dumps(assignment_result)