Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _hit_xml_to_object(hits):
if not isinstance(hits, list):
hits = [hits]
hits_data = [MTurkHIT({
'hitid': hit['HITId'],
'title': hit['Title'],
'status': hit['HITStatus'],
'max_assignments': hit['MaxAssignments'],
'number_assignments_completed': hit['NumberOfAssignmentsCompleted'],
'number_assignments_pending': hit['NumberOfAssignmentsPending'],
'number_assignments_available': hit['NumberOfAssignmentsAvailable'],
'creation_time': hit['CreationTime'],
'expiration': hit['Expiration'],
'is_expired': datetime.datetime.now(hit['Expiration'].tzinfo) >= hit['Expiration'],
'duration_in_seconds': hit['AssignmentDurationInSeconds'],
'reward': hit['Reward'],
'description': hit['Description'],
'number_submissions_needing_action': hit['MaxAssignments'] - hit['NumberOfAssignmentsCompleted'] - hit['NumberOfAssignmentsPending'] - hit['NumberOfAssignmentsAvailable']
}) for hit in hits]
return hits_data
def default(self, obj):
if isinstance(obj, (PsiturkException, WrapperResponse)):
return obj.to_dict()
elif isinstance(obj, Exception):
return {
'exception': type(obj).__name__,
'message': str(obj)
}
elif isinstance(obj, MTurkHIT):
return obj.__dict__
return JSONEncoder.default(self, obj)