Skip to content

Instantly share code, notes, and snippets.

@dirkcuys
Created December 3, 2013 13:55
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 dirkcuys/7769495 to your computer and use it in GitHub Desktop.
Save dirkcuys/7769495 to your computer and use it in GitHub Desktop.
def create_taste_profiles(signups):
""" Create EchoNest taste profiles for every signup in a sequence """
config.ECHO_NEST_API_KEY = settings.ECHONEST_API_KEY
for signup_index, signup in enumerate(signups):
artists = list(set([ signup['questions'].get('artist{0}'.format(i)) for i in range(1,6) ]))
artists.sort()
print("Updating profile {0} of {1}".format(signup_index+1, len(signups)))
taste_profile = None
try:
taste_profile = catalog.get_catalog_by_name(signup['email'])
except:
pass
if not taste_profile:
taste_profile = catalog.create_catalog_by_name(signup['email'], 'artist')
items = []
for i, artist in enumerate(artists):
item = {
'item_id': u'{0}-{1}'.format(signup['email'], i),
'artist_name': artist,
'favorite': True
}
items += [{'action': 'update', 'item': item}]
taste_profile.update(items)
time.sleep(60/40.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment