From dde80bae6ac555d911a5b17c2b287e4aa05e5fe3 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sat, 21 Jun 2014 18:19:04 -0400 Subject: [PATCH] Added example that gets a user's starred items --- examples/user_starred_playlist.py | 32 +++++++++++++++++++++++++++++++ examples/util.py | 2 +- setup.py | 2 +- spotipy/__init__.py | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 examples/user_starred_playlist.py diff --git a/examples/user_starred_playlist.py b/examples/user_starred_playlist.py new file mode 100644 index 0000000..2aa60cc --- /dev/null +++ b/examples/user_starred_playlist.py @@ -0,0 +1,32 @@ +# shows a user's starred playlist + +import sys +import spotipy +import util +import spotipy.oauth2 as oauth2 + + + +if len(sys.argv) > 1: + username = sys.argv[1] +else: + print "Whoops, need your username!" + print "usage: python user_playlists.py [username]" + sys.exit() + +token = util.prompt_for_user_token(username) + +if token: + sp = spotipy.Spotify(auth=token) + results = sp.user_playlist(username) + tracks = results['tracks'] + which = 1 + while tracks: + for item in tracks['items']: + track = item['track'] + print which, track['name' ], ' --', track['artists'][0]['name'] + which += 1 + tracks = sp.next(tracks) + +else: + print "Can't get token for", username diff --git a/examples/util.py b/examples/util.py index 8173e7e..46e1917 100644 --- a/examples/util.py +++ b/examples/util.py @@ -5,7 +5,7 @@ import os import subprocess import spotipy.oauth2 as oauth2 -def prompt_for_user_token(username, scope): +def prompt_for_user_token(username, scope=None): ''' prompts the user to login if necessary and returns the user token suitable for use with the spotipy.Spotify constructor diff --git a/setup.py b/setup.py index 08d0410..7b9a0c2 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='SpotipyWebApi', - version='1.42', + version='1.43', description='simple client for the Spotify Web API', author="@plamere", author_email="paul@echonest.com", diff --git a/spotipy/__init__.py b/spotipy/__init__.py index 5969c70..cc97826 100644 --- a/spotipy/__init__.py +++ b/spotipy/__init__.py @@ -203,7 +203,7 @@ class Spotify(object): ''' return self.get("users/%s/playlists" % user) - def user_playlist(self, user, playlist_id, fields=None): + def user_playlist(self, user, playlist_id = None, fields=None): ''' Gets playlist of a user ''' if playlist_id == None: