Last active
March 8, 2020 01:32
-
-
Save makispl/dffdbb122c9686c2cf03a6d076e01cc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch_playlists(sp, username): | |
""" | |
Returns the user's playlists. | |
""" | |
id = [] | |
name = [] | |
num_tracks = [] | |
# Make the API request | |
playlists = sp.user_playlists(username) | |
for playlist in playlists['items']: | |
id.append(playlist['id']) | |
name.append(playlist['name']) | |
num_tracks.append(playlist['tracks']['total']) | |
# Create the final df | |
df_playlists = pd.DataFrame({"id":id, "name": name, "#tracks": num_tracks}) | |
return df_playlists | |
playlists = fetch_playlists(sp,username) | |
playlists = playlists[:4].copy() | |
playlists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment