spotipy/examples/show_related.py

26 lines
581 B
Python
Raw Normal View History

2014-07-07 15:25:19 +00:00
# shows related artists for the given seed artist
import spotipy
import sys
import pprint
if len(sys.argv) > 1:
artist_name = sys.argv[1]
else:
artist_name = 'weezer'
sp = spotipy.Spotify()
result = sp.search(q='artist:' + artist_name, type='artist')
try:
name = result['artists']['items'][0]['name']
uri = result['artists']['items'][0]['uri']
related = sp.artist_related_artists(uri)
2015-06-05 09:07:28 +00:00
print('Related artists for', name)
2014-07-07 15:25:19 +00:00
for artist in related['artists']:
2015-06-05 09:07:28 +00:00
print(' ', artist['name'])
2014-07-07 15:25:19 +00:00
except:
2015-06-05 09:07:28 +00:00
print("usage show_related.py [artist-name]")
2014-07-07 15:25:19 +00:00