예제 #1
0
            # try except to catch Spotify max retries error
            try:
                # get audio features
                attribute_info(sp, mood, track_uri, track_details)
            except:
                print("Connection refused by the server...")
                print("sleeping for 5 seconds...")
                time.sleep(5)
                print("Slept for 5 seconds, time to continue...")
                continue

    return track_dict


sp = OAuth()
token = sp.get_token()

if token:
    # get angry songs
    track_dict = {}
    sp = spotipy.Spotify(auth=token)
    print(type(sp))
    track_dict = get_songs(sp, 0, num_angry, angry,
                           track_dict)  # get info about angry songs
    print(len(track_dict))

    # turn dictionary of songs into a dataframe
    df = pd.DataFrame.from_dict(track_dict, orient='index')
    df.rename(columns={'Unnamed: 0': 'track_uri'}, inplace=True)
    print(df)
    # df to csv file