如何使用boto3客户端删除仍然可用的HIT

问题描述 投票:0回答:1

我有一些已发布的HIT可供工人使用。现在我想删除它们,尽管它们还没有被工人完成。根据这个文档,它是不可能的:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/mturk.html#MTurk.Client.delete_hit

只能删除处于可审核状态的HIT。

但是使用命令行界面似乎是可能的:https://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkCLT/CLTReference_DeleteHITsCommand.html

我的问题是,我能以某种方式完成使用boto3客户端删除不可审查的HIT的命令行行为吗?

python boto3 mechanicalturk
1个回答
3
投票

部分解决方案是将“可分配”HIT设置为立即过期。我用这个脚本来清理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')
© www.soinside.com 2019 - 2024. All rights reserved.