Created
December 3, 2013 13:55
-
-
Save dirkcuys/7769495 to your computer and use it in GitHub Desktop.
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
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