Created
December 3, 2013 14:01
-
-
Save dirkcuys/7769584 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_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