Skip to content

Instantly share code, notes, and snippets.

@dirkcuys
Created December 3, 2013 14:01
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/7769584 to your computer and use it in GitHub Desktop.
Save dirkcuys/7769584 to your computer and use it in GitHub Desktop.
def create_echonest_graph():
""" Build a dictionary with the distances between all taste profiles """
"""
{
'<profile_id>': {'name': '<profile_name>', 'suggest': {'<profile_id>': <score>, '<profile_id>': <score>, ...} },
'<profile_id>': {'name': '<profile_name>', 'suggest': {'<profile_id>': <score>, '<profile_id>': <score>, ...} },
...
'<profile_id>': {'name': '<profile_name>', 'suggest': {'<profile_id>': <score>, '<profile_id>': <score>, ...} },
}
"""
config.ECHO_NEST_API_KEY = settings.ECHONEST_API_KEY
url = 'http://developer.echonest.com/api/v4/catalog/similar'
signups = models.get_signups()
adjacency_list = {}
for i, signup in enumerate(signups):
print("Fetching taste profile {0} of {1}".format(i+1, len(signups)))
taste_profile = catalog.get_catalog_by_name(signup['email'])
params = {
'api_key': settings.ECHONEST_API_KEY,
'id': taste_profile.id,
'results': 40
}
resp = requests.get(url, params=params)
profile_scores = {}
for profile in resp.json()['response'].get('catalogs', []):
profile_scores[profile['id']] = profile['score']
adjacency_list[taste_profile.id] = {'name': signup['email'], 'suggest': profile_scores}
return adjacency_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment