diff --git a/spotifyvis/utils.py b/spotifyvis/utils.py index b7a95c7..7898141 100644 --- a/spotifyvis/utils.py +++ b/spotifyvis/utils.py @@ -127,7 +127,7 @@ def save_audio_features(headers, track_id, track): response = requests.get("https://api.spotify.com/v1/audio-features/{}".format(track_id), headers = headers).json() if 'error' in response: - return {} + return # Data that we don't need useless_keys = [ diff --git a/spotifyvis/views.py b/spotifyvis/views.py index 8b9e3b8..a21b6d3 100644 --- a/spotifyvis/views.py +++ b/spotifyvis/views.py @@ -203,8 +203,11 @@ def get_audio_feature_data(request, audio_feature, client_secret): 'data_points': [], } for track in user_tracks: - audio_feature_obj = AudioFeatures.objects.get(track=track) - response_payload['data_points'].append(getattr(audio_feature_obj, audio_feature)) + try: + audio_feature_obj = AudioFeatures.objects.get(track=track) + response_payload['data_points'].append(getattr(audio_feature_obj, audio_feature)) + except AudioFeatures.DoesNotExist: + continue return JsonResponse(response_payload) # }}} get_audio_feature_data #