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