Esempio n. 1
0
def test():
    token = startup.getAccessToken()
    if len(token) == 0:
        return redirect(url_for('index'))
    access_token = token[0]
    artists = plotify_data.get_top_genres(access_token)
    data = pd.DataFrame.from_records(artists)
    data.columns = ['id', 'name', 'count']
    return data.to_csv(index=False)
Esempio n. 2
0
def getUserLibrary():
    sp = spotipy.Spotify(auth=startup.getAccessToken()[0])

    results = sp.current_user_saved_tracks()
    output = []

    for item in results['items']:
        track = item['track']
        output.append(track['name'] + ' - ' + track['artists'][0]['name'])

    return output
Esempio n. 3
0
def getUserPlaylistsById():
    sp = spotipy.Spotify(auth=startup.getAccessToken()[0])

    playlists = sp.current_user_playlists()
    output = []

    for playlist in playlists['items']:
        name = playlist['id']
        output.append(name)

    return output
Esempio n. 4
0
def getSongsInPlaylist(id):
    sp = spotipy.Spotify(auth=startup.getAccessToken()[0])

    playlist = sp.playlist_tracks(id)
    output = []

    for track in playlist['items']:
        output.append(track['track']['name'] + " by " +
                      track['track']['artists'][0]['name']
                      )  # + " by " + track['artists'][0]['name'])

    print(output)
    return output
Esempio n. 5
0
def main():
    response = startup.getUser()
    token = startup.getAccessToken()
    if len(token) == 0:
        return redirect(url_for('index'))
    access_token = token[0]
    artists = plotify_data.get_top_genres(access_token)
    genres = [item[1] for item in artists][:10]
    username, prof_pic = plotify_data.get_username(access_token)
    stracks = plotify_data.get_top_tracks(access_token, 'short_term')
    sartists = plotify_data.get_top_artists(access_token, 'short_term')
    mtracks = plotify_data.get_top_tracks(access_token, 'medium_term')
    martists = plotify_data.get_top_artists(access_token, 'medium_term')
    ltracks = plotify_data.get_top_tracks(access_token, 'long_term')
    lartists = plotify_data.get_top_artists(access_token, 'long_term')
    years, count = plotify_data.get_track_data(access_token, 'long_term')
    legend = 'Tracks by Year'
    danceable, averaged, plist_names = plotify_data.get_playlist_metrics(
        access_token)
    radar_labels = [
        'danceability', 'energy', 'speechiness', 'acousticness',
        'instrumentalness', 'liveness', 'valence'
    ]
    return render_template('index.html',
                           username=username,
                           genres=genres,
                           stracks=stracks,
                           sartists=sartists,
                           mtracks=mtracks,
                           martists=martists,
                           ltracks=ltracks,
                           lartists=lartists,
                           prof_pic=prof_pic,
                           values=count,
                           labels=years,
                           legend=legend,
                           danceable=danceable,
                           averaged=averaged,
                           radar_labels=radar_labels,
                           plist_names=plist_names)
Esempio n. 6
0
        sentimentDesc = 'The Sentiment Analysis score of the current headlines is ' + str(sentiment) + '. This suggests their sentiment is positive.'
        session['sDesc'] = sentimentDesc
    if sentiment < negThresh:
        sentimentDesc = 'The Sentiment Analysis score of the current headlines is ' + str(sentiment) + '. This suggests their sentiment is negative.'
        session['sDesc'] = sentimentDesc
    return render_template('index.html',page=header,news=True,titles=titles,info=titles[0],n=numArticles,sentimentDesc=sentimentDesc)

@app.route('/spotify/', methods=['POST'])
def spotify_login():
    response = startup.getUser()
    return redirect(response)

@app.route('/callback/')
def test():
    startup.getUserToken(request.args['code'])
    token = startup.getAccessToken()
    token = token[0]
    session['token'] = token
    success = None
    sentimentDesc = session['sDesc']
    return render_template('index.html',authgranted=True,titles=True,sentimentDesc=sentimentDesc)

@app.route('/oppose/', methods = ['GET','POST'])
def opposeHeadlines():
    token = session['token']
    if token:
        sp = spotipy.Spotify(auth=token)
        user_data = sp.current_user()
        dateTimeStr = datetime.strftime(datetime.now(), '%Y-%m-%d, %H:%M')
        sentiment = analyseHeadlines(adjPos,adjNeg)
        if sentiment >= posThresh: