Repackaged for saner imports

This commit is contained in:
Paul Lamere 2014-05-18 07:08:51 -04:00
parent a48feaab66
commit 8dcaf7dba6
5 changed files with 21 additions and 15 deletions

View File

@ -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

View File

@ -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)
pprint.pprint(playlists)

View File

@ -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'],)

View File

@ -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
'''

View File

@ -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']
return response.json()['access_token']