pretty printed list-hits
This commit is contained in:
parent
878735c0ec
commit
967590981c
3 changed files with 25 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
config.local.yml
|
||||
*.sla
|
||||
*.pyc
|
||||
|
||||
|
|
|
@ -40,6 +40,12 @@ if __name__ == "__main__":
|
|||
action='store_true',
|
||||
help='fetch HIT status and assignments from MTurk'
|
||||
)
|
||||
argParser.add_argument(
|
||||
'--list-hits',
|
||||
'-lh',
|
||||
action='store_true',
|
||||
help='For debugging: list all hits using API'
|
||||
)
|
||||
argParser.add_argument(
|
||||
'--for-real',
|
||||
action='store_true',
|
||||
|
@ -67,6 +73,8 @@ if __name__ == "__main__":
|
|||
|
||||
if args.update:
|
||||
connection.load_new_submissions()
|
||||
if args.list_hits:
|
||||
connection.list_hits()
|
||||
elif args.publish:
|
||||
if args.publish not in batch_files:
|
||||
raise Exception(f'Not a valid batch. Use one of {batches=}')
|
||||
|
|
|
@ -38,6 +38,21 @@ class Connection():
|
|||
endpoint_url = MTURK_REAL if self.config['for_real'] else MTURK_SANDBOX
|
||||
)
|
||||
|
||||
def list_hits(self):
|
||||
next_token = None
|
||||
all = 0
|
||||
while True:
|
||||
logger.info('fetch hits:')
|
||||
r = self.mturk.list_hits() if not next_token else self.mturk.list_hits(NextToken = next_token)
|
||||
print(yaml.dump(r['HITs'], sort_keys=False, default_flow_style=False))
|
||||
all += len(r['HITs'])
|
||||
if 'NextToken' in r and r['NextToken']:
|
||||
next_token = r['NextToken']
|
||||
else:
|
||||
break
|
||||
logger.info(f'Fetched {all} hits')
|
||||
|
||||
|
||||
def load_new_submissions(self):
|
||||
hit_files = glob.glob('batches/hits/*.json')
|
||||
for hit_file in hit_files:
|
||||
|
|
Loading…
Reference in a new issue