问题
I have some published HITs available to workers. Now I want to delete them although they haven't been finished by the workers. According to this documentation, it is not possible: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/mturk.html#MTurk.Client.delete_hit
Only HITs in reviewable state can be deleted.
But using the command line interface it seems to be possible: https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html
My question is, can I somehow accomplish the command line behaviour of deleting not reviewable HITs using boto3 client?
回答1:
The partial solution is to set an 'Assignable' HIT to expire immediately. I use this script for cleaning up the Mechanical Turk Sandbox:
import boto3
from datetime import datetime
# Get the MTurk client
mturk=boto3.client('mturk',
aws_access_key_id="aws_access_key_id",
aws_secret_access_key="aws_secret_access_key",
region_name='us-east-1',
endpoint_url="https://mturk-requester-sandbox.us-east-1.amazonaws.com",
)
# Delete HITs
for item in mturk.list_hits()['HITs']:
hit_id=item['HITId']
print('HITId:', hit_id)
# Get HIT status
status=mturk.get_hit(HITId=hit_id)['HIT']['HITStatus']
print('HITStatus:', status)
# If HIT is active then set it to expire immediately
if status=='Assignable':
response = mturk.update_expiration_for_hit(
HITId=hit_id,
ExpireAt=datetime(2015, 1, 1)
)
# Delete the HIT
try:
mturk.delete_hit(HITId=hit_id)
except:
print('Not deleted')
else:
print('Deleted')
来源:https://stackoverflow.com/questions/54198700/how-to-delete-still-available-hits-using-boto3-client