mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-07-30 14:00:18 +00:00
improved example
This commit is contained in:
25
examples/user_public_playlists.py
Normal file
25
examples/user_public_playlists.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Gets all the public playlists for the given
|
||||
# user. Uses Client Credentials flow
|
||||
#
|
||||
|
||||
import sys
|
||||
import spotipy
|
||||
from spotipy.oauth2 import SpotifyClientCredentials
|
||||
|
||||
client_credentials_manager = SpotifyClientCredentials()
|
||||
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||
|
||||
user = 'spotify'
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
user = sys.argv[1]
|
||||
|
||||
playlists = sp.user_playlists(user)
|
||||
|
||||
while playlists:
|
||||
for i, playlist in enumerate(playlists['items']):
|
||||
print("%4d %s %s" % (i + 1 + playlists['offset'], playlist['uri'], playlist['name']))
|
||||
if playlists['next']:
|
||||
playlists = sp.next(playlists)
|
||||
else:
|
||||
playlists = None
|
Reference in New Issue
Block a user