def moodtape(): global final_mood if(final_mood=='Happy'): mood = 1.0 mood=(round(random.uniform(0.8, 0.1), 2)) elif(final_mood=='Sad'): mood=0.1 mood = (round(random.uniform(0.1, 0.3), 2)) elif(final_mood=='Neutral'): mood=0.5 mood = (round(random.uniform(0.4, 0.7), 2)) # username = request.form['username'] mood = float(mood) # token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) spotify_auth = authenticate_spotify(token) top_artists = aggregate_top_artists(spotify_auth) top_tracks = aggregate_top_tracks(spotify_auth, top_artists) selected_tracks = select_tracks(spotify_auth, top_tracks, mood) #all_playlists='https://api.spotify.com/v1/users/'+username+'/playlists' #x = requests.get(all_playlists,params {Authorization: 49c660ae3c0242deb395127c50aa4971}) #print(x.response) #resp_dict = json.load(x) playlist = create_playlist(spotify_auth, selected_tracks, mood,final_mood) playlist='https://open.spotify.com/playlist/'+playlist.split(':')[2] print(playlist) return render_template('playlist.html', playlist=playlist,mood=final_mood)
def moodtape(): mood = request.form['text'] # username = request.form['username'] mood = float(mood) # token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) spotify_auth = authenticate_spotify(token) top_artists = aggregate_top_artists(spotify_auth) top_tracks = aggregate_top_tracks(spotify_auth, top_artists) selected_tracks = select_tracks(spotify_auth, top_tracks, mood) playlist = create_playlist(spotify_auth, selected_tracks, mood) return render_template('playlist.html', playlist=playlist)
def login(): global spotify_auth global top_artists global top_tracks if request.method == 'POST': username = request.form['username'] token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) spotify_auth = authenticate_spotify(token) top_artists = aggregate_top_artists(spotify_auth) top_tracks = aggregate_top_tracks(spotify_auth, top_artists) return redirect(url_for('predict')) else: return render_template('username.html')