8-Bit Borges
8-Bit Borges

Reputation: 10033

Python :: passing a list as parameter

responses in pyen, a thin library for music data, returns dictionaries in this fashion:

{u'id': u'AR6SPRZ1187FB4958B', u'name': u'Wilco'}

I'm looping through and printing artists:

response = en.get('artist/search', artist_location='Chicago')

artists = response['artists']
for artist in artists:
   sys.stdout.write("song by {}\n".format(artist['name']))

but I'd like to pass a list of ids here:

  response = en.get('song/search', artist_ids = ?) //pass a list here?
  for song in response['songs']:
  sys.stdout.write("\t{}\n".format(song['title']))

Is this possible? How?

Upvotes: 3

Views: 89

Answers (2)

Steven Moseley
Steven Moseley

Reputation: 16345

If you look at the Echo Nest API, you'll see that song search by artist_id doesn't support multiple params.

Thus, that's a restriction on pyen, as well, being a consumer of that API.

Instead, you'll have to print songs in a loop of requests:

artist_ids = ['AR54RGR1187FB51D10', 'AR6SPRZ1187FB4958B', 'AR5KAA01187FB5AEB7']
for artist_id in artist_ids:
    for song in en.get('song/search', artist_id=artist_id).get('songs', []):
        sys.stdout.write("\t{}\n".format(song['title']))

Upvotes: 2

alecxe
alecxe

Reputation: 474081

pyen is a very thin wrapper, you should always check the EchoNest API docs directly. According to the API documentation, the song/search endpoint does not accept multiple artist_ids.

Upvotes: 3

Related Questions