From 8dcaf7dba6cafb4ba1e40f7598208819f141c6b7 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sun, 18 May 2014 07:08:51 -0400 Subject: [PATCH] Repackaged for saner imports --- README.md | 9 +++------ examples/user_playlists.py | 19 ++++++++++++------- setup.py | 2 +- spotipy.py => spotipy/__init__.py | 3 +++ oauth2.py => spotipy/oauth2.py | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) rename spotipy.py => spotipy/__init__.py (99%) rename oauth2.py => spotipy/oauth2.py (96%) diff --git a/README.md b/README.md index 3321fd4..6b5b2ae 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,6 @@ the library simply by downloading the distribution, unpack it and install in the - [Requests](https://github.com/kennethreitz/requests) - spotipy requires the requests package to be installed -## Limitations -This version of the library does not support user authentication - - ## Quick Start To get started: @@ -51,6 +47,7 @@ A full set of examples can be found in the [Spotipy examples directory](https:// - artist_top_tracks - gets info about an artist's top tracks - user - gets profile info for a user - search - searches for artists, albums or tracks + - simple oauth flow Refer to the [Spotify API documentation](https://developer.spotify.com/spotify-web-api/) for details on the methods and parameters. @@ -61,7 +58,6 @@ Methods that take item IDs (such as the track, album and artist methods) accept - 3HfB5hBU0dmBt8T0iCmH42 - ## Reporting Issues If you have suggestions, bugs or other issues specific to this library, file them [here](https://github.com/plamere/spotipy/issues) or contact me @@ -69,6 +65,7 @@ at [paul@echonest.com](mailto:paul@echonest.com). Or just send me a pull request ## Version +- 1.1 - 04/05/2014 - Initial release - 1.0 - 04/05/2014 - Initial release -- 1.1 - 05/16/2014 - Adapt to web API changes. Early auth support. +- 1.1 - 05/18/2014 - Repackaged for saner imports diff --git a/examples/user_playlists.py b/examples/user_playlists.py index bfdad1a..c1f296d 100644 --- a/examples/user_playlists.py +++ b/examples/user_playlists.py @@ -2,22 +2,27 @@ import pprint import sys +import os import spotipy -import oauth2 +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]" + print "Whoops, need your username!" + print "usage: python user_playlists.py [username]" sys.exit() # Create these via developer.spotify.com/my-applications -client_id = '' -client_secret = '' -redirect_uri = '' +client_id = os.getenv('CLIENT_ID') +client_secret = os.getenv('CLIENT_SECRET') +redirect_uri = os.getenv('REDIRECT_URI') + +print 'client_id', client_id +print 'client_secret', client_secret +print 'redirect_uri', redirect_uri # Oauth flow sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri) @@ -31,4 +36,4 @@ access_token = sp_oauth.get_access_token(code) sp = spotipy.Spotify(auth=access_token) playlists = sp.user_playlists(username) -pprint.pprint(playlists) \ No newline at end of file +pprint.pprint(playlists) diff --git a/setup.py b/setup.py index e41679c..80fd48f 100644 --- a/setup.py +++ b/setup.py @@ -9,4 +9,4 @@ setup( author_email="paul@echonest.com", url='http://github.com/plamere/spotipy', install_requires=['requests>=1.0', ], - py_modules=['spotipy'],) + py_modules=['spotipy', 'spotify_oauth2'],) diff --git a/spotipy.py b/spotipy/__init__.py similarity index 99% rename from spotipy.py rename to spotipy/__init__.py index f377a43..3f77646 100644 --- a/spotipy.py +++ b/spotipy/__init__.py @@ -1,9 +1,12 @@ # coding: utf-8 from __future__ import print_function + import base64 import requests +__all__ = ['oauth2'] + ''' A simple and thin Python library for the Spotify Web API ''' diff --git a/oauth2.py b/spotipy/oauth2.py similarity index 96% rename from oauth2.py rename to spotipy/oauth2.py index 5d15ed8..e623344 100644 --- a/oauth2.py +++ b/spotipy/oauth2.py @@ -2,6 +2,7 @@ import base64 import urllib import requests +print ('oauth2 is here') class SpotifyOauthError(Exception): pass @@ -53,4 +54,4 @@ class SpotifyOAuth(object): response = requests.post(self.OAUTH_TOKEN_URL, data=payload, headers=headers, verify=True) if response.status_code is not 200: raise SpotifyOauthError(response.reason) - return response.json()['access_token'] \ No newline at end of file + return response.json()['access_token']