def select_one_album(albums):
"""Display the albums returned by search api.
:params albums: API['result']['albums']
:return: a Album object.
"""
if len(albums) == 1:
select_i = 0
else:
table = PrettyTable(['Sequence', 'Album Name', 'Artist Name'])
for i, album in enumerate(albums, 1):
table.add_row([i, album['name'], album['artist']['name']])
click.echo(table)
select_i = click.prompt('Select one album', type=int, default=1)
while select_i < 1 or select_i > len(albums):
select_i = click.prompt('Error Select! Select Again', type=int)
album_id = albums[select_i-1]['id']
album_name = albums[select_i-1]['name']
album = Album(album_id, album_name)
return album
评论列表
文章目录