Skip to content

Instantly share code, notes, and snippets.

@plamere
Created August 3, 2014 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plamere/e41f5a163566dddbeba4 to your computer and use it in GitHub Desktop.
Save plamere/e41f5a163566dddbeba4 to your computer and use it in GitHub Desktop.
iterating through artists with spotipy to get the top tracks
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