Skip to content

Instantly share code, notes, and snippets.

@makispl
Last active March 8, 2020 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makispl/dffdbb122c9686c2cf03a6d076e01cc4 to your computer and use it in GitHub Desktop.
Save makispl/dffdbb122c9686c2cf03a6d076e01cc4 to your computer and use it in GitHub Desktop.
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