def get_all_items():
"""
Get all items
"""
if DATASTORE == "DynamoDB":
response = table.scan()
if response['Count'] == 0:
return []
else:
return response['Items']
else:
# We want info_hash, peers, and completed.
items = []
# There must be a better way to do this.
# Also, it should probably be done as a recurring function and cache,
# not dynamically every time.
for key in s3_client.list_objects(Bucket=BUCKET_NAME)['Contents']:
if 'peers.json' in key['Key']:
remote_object = s3.Object(BUCKET_NAME, key['Key']).get()
content = remote_object['Body'].read().decode('utf-8')
torrent_info = json.loads(content)
item = {
'info_hash': torrent_info['info_hash'],
'peers': torrent_info['peers'],
'completed': torrent_info['completed']
}
items.append(item)
return items
###
# Utility
###
# Helper class to convert a DynamoDB item to JSON.
评论列表
文章目录