<s> import argparse , json , sys <EOL> import simpleamt <EOL> def process_assignments ( mtc , hit_id ) : <EOL> results = [ ] <EOL> assignments = mtc . get_assignments ( hit_id ) <EOL> for a in assignments : <EOL> if a . AssignmentStatus in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> try : <EOL> output = json . loads ( a . answers [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . fields [ <NUM_LIT:0> ] ) <EOL> except ValueError as e : <EOL> print >> sys . stderr , ( '<STR_LIT>' <EOL> % ( a . AssignmentId , a . WorkerId ) ) <EOL> continue <EOL> results . append ( { <EOL> '<STR_LIT>' : a . AssignmentId , <EOL> '<STR_LIT>' : hit_id , <EOL> '<STR_LIT>' : a . WorkerId , <EOL> '<STR_LIT>' : json . loads ( a . answers [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . fields [ <NUM_LIT:0> ] ) , <EOL> } ) <EOL> return results <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( parents = [ simpleamt . get_parent_parser ( ) ] ) <EOL> args = parser . parse_args ( ) <EOL> mtc = simpleamt . get_mturk_connection_from_args ( args ) <EOL> results = [ ] <EOL> if args . hit_ids_file is None : <EOL> for hit in mtc . get_all_hits ( ) : <EOL> results += process_assignments ( mtc , hit . HITId ) <EOL> else : <EOL> with open ( args . hit_ids_file , '<STR_LIT:r>' ) as f : <EOL> for line in f : <EOL> hit_id = line . strip ( ) <EOL> results += process_assignments ( mtc , hit_id ) <EOL> for assignment_result in results : <EOL> print json . dumps ( assignment_result ) </s>
