Esempio n. 1
0
 def test_generate_playlist_pos_seeds_under_5_valid_only_genres(self):
     test_url = spotify.generate_playlist(handle='@SomePositiveSeeds',
                                          seeds=(["rock", "hip-hop"], []))
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     assert len(
         test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
Esempio n. 2
0
 def test_generate_playlist_neg_seeds_neg_feature(self):
     test_url = spotify.generate_playlist(handle='@LowAccousitcs',
                                          seeds=(["cheese", "rock"],
                                                 ["acousticness"]))
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     assert len(
         test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
Esempio n. 3
0
 def test_generate_playlist_only_handle(self):
     test_url = spotify.generate_playlist(handle='@SampleHandle')
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     correct_tracks = spotify_config.SOUNDS_OF_SILENCE
     assert len(test_playlist_tracks.get('items')) == 3
     for test_track in test_playlist_tracks.get('items'):
         assert test_track.get('track').get('id') in correct_tracks
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
Esempio n. 4
0
 def test_generate_playlist_pos_seeds_genres_some_invalid(self):
     test_url = spotify.generate_playlist(
         handle='@AllInvalidSeeds',
         seeds=(["cheese", "valence", "loudness", "test", "Franklin"], []))
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     correct_tracks = spotify_config.SOUNDS_OF_SILENCE
     assert len(test_playlist_tracks.get('items')) == 3
     for test_track in test_playlist_tracks.get('items'):
         assert test_track.get('track').get('id') in correct_tracks
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
Esempio n. 5
0
 def test_generate_playlist_lots_of_seeds(self):
     test_url = spotify.generate_playlist(
         handle='@ManySeeds',
         seeds=([
             "cheese", "valence", "loudness", "test", "Franklin", "rock",
             "hip-hop", "danceability", "metal", "alt-rock"
         ], ["classical", "loudness", "wow", "acousticness"]))
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     assert len(
         test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
Esempio n. 6
0
 def test_generate_playlist_pos_seeds_over_5_invalid(self):
     test_url = spotify.generate_playlist(
         handle='@ManyPositiveInvalidSeeds',
         seeds=([
             "valence", "rock", "hip-hop", "cheese", "classical", "disco",
             "electronic", "folk", "funk", "metal"
         ], []))
     expected_prefix = spotify_config.PLAYLIST_PREFIX
     assert test_url.find(expected_prefix) == 0
     assert len(test_url) > len(expected_prefix)
     sp = spotipy.Spotify(spotify.get_access_token())
     test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url)
     assert len(
         test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE
     sp.user_playlist_unfollow(
         user=spotify_config.SONGBIRD_USER_ID,
         playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def process_spotify(id):
    app = base_app.create_app()
    with app.app_context():
        print("### Starting spotify job for id %i ###" % id)

        recommendation = Recommendation.query.get(id)

        attributes = {
            "Openness": recommendation.openness / 100,
            "Conscientiousness": recommendation.conscientiousness / 100,
            "Extraversion": recommendation.extraversion / 100,
            "Agreeableness": recommendation.agreeableness / 100,
            "Emotional Range": recommendation.neuroticism / 100
        }

        genres = tweet_genres.get_genres_from_profile(attributes)
        playlist = spotify.generate_playlist(recommendation.handle, genres)
        recommendation.playlist = playlist
        recommendation.genres = ", ".join(genres[0])
        print(recommendation.genres)

        db.session.commit()

        print("### Finished spotify job for id %i ###" % id)