示例#1
0
def interface():
    """Endpoint that rejects and approves work.
    """
    et = EasyTurk(sandbox=False)
    if request.method != 'POST':
        return 'Fail'
    assignment_ids = json.loads(request.form['assignment_ids'])
    approve = json.loads(request.form['approve'])
    for assignment_id in assignment_ids:
        if approve:
            et.approve_assignment(assignment_id)
        else:
            et.reject_assignment(assignment_id)
    eresults_file = request.form['eresults_file']
    results = json.load(open(eresults_file))
    for hit in results['hits']:
        if hit['assignment_id'] in assignment_ids:
            hit['approve'] = approve
    json.dump(results, open(eresults_file, 'w'))
    return 'Succcess'
示例#2
0
def fetch_completed_hits(hit_ids, approve=True):
    """Grabs the results for the hit ids.

    Args:
        hit_ids: A list of hit ids to fetch.
        approve: Whether to approve the hits that have been submitted.

    Returns:
        A dictionary from hit_id to the result, if that hit_id has
        been submitted.
    """
    et = EasyTurk()
    output = {}
    for hit_id in hit_ids:
        results = et.get_results(hit_id, reject_on_fail=False)
        if len(results) > 0:
            output[hit_id] = results
            if approve:
                for assignment in results:
                    assignment_id = assignment['assignment_id']
                    et.approve_assignment(assignment_id)
    return output