Created
August 3, 2014 16:27
-
-
Save plamere/e41f5a163566dddbeba4 to your computer and use it in GitHub Desktop.
iterating through artists with spotipy to get the top tracks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for start in xrange(0, 10000, page_size): | |
response = en.get('catalog/read', id=tpid, start=start, | |
results=page_size, bucket=['id:spotify']) | |
if len(response['catalog']['items']) == 0: | |
break | |
spaids = [] | |
for item in response['catalog']['items']: | |
if 'artist_name' in item: | |
spid = item['request']['item_id'] | |
spaids.append(spid) | |
spartists = sp.artists(spaids) | |
for spartist in spartists['artists']: | |
image = getBestImageUrl(spartist) | |
top_tracks = get_top_tracks(spartist['uri']) | |
if image == None: | |
print len(out), "Missing image for", spartist['name'] | |
if len(top_tracks) == 0: | |
print len(out), "Missing tracks for", spartist['name'] | |
simple_artist = { | |
'name' : spartist['name'], | |
'uri' : spartist['uri'], | |
'image': image, | |
'tracks' : top_tracks | |
} | |
out.append(simple_artist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment