From e4c66401c1b4a577765419724de1e50959009320 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 21:19:24 +0300 Subject: [PATCH 1/7] Add Travis CI and .gitignore --- .gitignore | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51cbe85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +bin/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Rope +.ropeproject + +# Django stuff: +*.log +*.pot + +# Sphinx documentation +docs/_build/ + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c0ec53f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,27 @@ +language: python + +python: + - 2.6 + - 2.7 + - 3.2 + - 3.3 + - 3.4 + - pypy + +script: + - python setup.py install + - coverage run --source=spotipy.py tests/tests.py + +after_success: + - coverage report + - coveralls + - pip install pep8 pyflakes + - pep8 PIL/*.py + - pyflakes PIL/*.py + +matrix: + allow_failures: + - python: 2.6 + - python: 3.2 + - python: 3.4 + - python: pypy From 724b4e3cd53a2f9848cc417a0dc143870a1ef375 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 21:27:09 +0300 Subject: [PATCH 2/7] pip install coveralls --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c0ec53f..a86b4bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ python: - 3.4 - pypy +install: + - pip install coveralls + script: - python setup.py install - coverage run --source=spotipy.py tests/tests.py From 4c5d56768fb2c9e125c56ad83404d59f3f655ad5 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 21:34:16 +0300 Subject: [PATCH 3/7] Update .travis.yml --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a86b4bc..454cba2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,12 +19,10 @@ after_success: - coverage report - coveralls - pip install pep8 pyflakes - - pep8 PIL/*.py - - pyflakes PIL/*.py + - pep8 *.py tests/*.py + - pyflakes *.py tests/*.py matrix: allow_failures: - - python: 2.6 - python: 3.2 - python: 3.4 - - python: pypy From 8a3ccd8b2a31b61873ef82ced4f0963f17c71f7c Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 21:44:15 +0300 Subject: [PATCH 4/7] Adjust coverage command for package install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 454cba2..49e95c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: script: - python setup.py install - - coverage run --source=spotipy.py tests/tests.py + - coverage run --include=*spotipy* tests/tests.py after_success: - coverage report From 6e8ae44c5a6ccffd594bf5f00155bbeb587b2fa5 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 21:52:57 +0300 Subject: [PATCH 5/7] pyflakes and some pep8 --- setup.py | 6 +++--- spotipy.py | 21 +++++++++------------ tests/tests.py | 15 +++++++-------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index 07bee83..922dbff 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,10 @@ from setuptools import setup setup( name='spotipy', - version='0.9', - description='simple client for The Spotify Web API', + version='0.9', + description='simple client for the Spotify Web API', author="@plamere", author_email="paul@echonest.com", url='http://github.com/plamere/spotipy', - install_requires=['requests>=1.0',], + install_requires=['requests>=1.0', ], py_modules=['spotipy'],) diff --git a/spotipy.py b/spotipy.py index 75d71e5..60e5663 100644 --- a/spotipy.py +++ b/spotipy.py @@ -1,20 +1,19 @@ import requests -import os -import time -import datetime -import json -import logging -''' A simple and thin python library for the Spotify Web API +''' A simple and thin Python library for the Spotify Web API ''' + class SpotifyException(Exception): def __init__(self, http_status, code, msg): self.http_status = http_status self.code = code self.msg = msg + def __str__(self): - return u'http status: {0}, code:{1} - {2}'.format(self.http_status, self.code, self.msg) + return u'http status: {0}, code:{1} - {2}'.format( + self.http_status, self.code, self.msg) + class Spotify(object): def __init__(self): @@ -30,17 +29,16 @@ class Spotify(object): raise SpotifyException(r.status_code, -1, u'the requested resource could not be found') return r.json() - - def get(self, method, args = None, **kwargs): + def get(self, method, args=None, **kwargs): if args: kwargs.update(args) return self._internal_call('GET', method, kwargs) def _error(self, msg): - print('ERROR - ' + msg); + print('ERROR - ' + msg) def _warn(self, msg): - print('warning:' + msg); + print('warning:' + msg) def track(self, track_id): ''' returns a single track given the track's ID, URN or URL @@ -84,7 +82,6 @@ class Spotify(object): tlist = [self._get_id('album', a) for a in albums] return self.get('albums/?ids=' + ','.join(tlist)) - def search(self, q, limit=10, offset=0, type='track'): ''' searches for an item ''' diff --git a/tests/tests.py b/tests/tests.py index 664996c..53b9d72 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,9 +1,7 @@ # -*- coding: latin-1 -*- import spotipy import unittest -import pprint -import logging class TestSpotipy(unittest.TestCase): @@ -14,7 +12,7 @@ class TestSpotipy(unittest.TestCase): pinkerton_urn = 'spotify:album:04xe676vyiTeYNXw15o9jT' weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu' pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL' - radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb' + radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb' bad_id = 'BAD_ID' @@ -23,7 +21,7 @@ class TestSpotipy(unittest.TestCase): def test_artist_urn(self): artist = self.spotify.artist(self.radiohead_urn) - self.assertTrue(artist['name'] == u'Radiohead') + self.assertTrue(artist['name'] == u'Radiohead') def test_artists(self): results = self.spotify.artists([self.weezer_urn, self.radiohead_urn]) @@ -32,7 +30,7 @@ class TestSpotipy(unittest.TestCase): def test_album_urn(self): album = self.spotify.album(self.pinkerton_urn) - self.assertTrue(album['name'] == u'Pinkerton') + self.assertTrue(album['name'] == u'Pinkerton') def test_albums(self): results = self.spotify.albums([self.pinkerton_urn, self.pablo_honey_urn]) @@ -41,15 +39,15 @@ class TestSpotipy(unittest.TestCase): def test_track_urn(self): track = self.spotify.track(self.creep_urn) - self.assertTrue(track['name'] == u'Creep') + self.assertTrue(track['name'] == u'Creep') def test_track_id(self): track = self.spotify.track(self.creep_id) - self.assertTrue(track['name'] == u'Creep') + self.assertTrue(track['name'] == u'Creep') def test_track_url(self): track = self.spotify.track(self.creep_url) - self.assertTrue(track['name'] == u'Creep') + self.assertTrue(track['name'] == u'Creep') def test_tracks(self): results = self.spotify.tracks([self.creep_url, self.el_scorcho_urn]) @@ -84,5 +82,6 @@ class TestSpotipy(unittest.TestCase): self.assertTrue(False) except spotipy.SpotifyException: self.assertTrue(True) + if __name__ == '__main__': unittest.main() From 28443a073951cf5faed805d01e0d743eec375d22 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 22:00:47 +0300 Subject: [PATCH 6/7] Run the examples (without coverage) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 49e95c9..0e99665 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ install: script: - python setup.py install - coverage run --include=*spotipy* tests/tests.py + - for file in examples/*.py; do python $file; done after_success: - coverage report From 411f648064d8ec87eed499ed61870cd291b366b5 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 5 Apr 2014 22:06:52 +0300 Subject: [PATCH 7/7] Py3 print (and pep8) --- examples/show_artist.py | 2 -- examples/show_track_info.py | 1 - examples/tracks.py | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/show_artist.py b/examples/show_artist.py index b07186a..bba54e7 100644 --- a/examples/show_artist.py +++ b/examples/show_artist.py @@ -9,8 +9,6 @@ if len(sys.argv) > 1: else: urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu' - sp = spotipy.Spotify() artist = sp.artist(urn) pprint.pprint(artist) - diff --git a/examples/show_track_info.py b/examples/show_track_info.py index 4a720ba..b286c0d 100644 --- a/examples/show_track_info.py +++ b/examples/show_track_info.py @@ -12,4 +12,3 @@ else: sp = spotipy.Spotify() track = sp.track(urn) pprint.pprint(track) - diff --git a/examples/tracks.py b/examples/tracks.py index 10883c8..3c520f2 100644 --- a/examples/tracks.py +++ b/examples/tracks.py @@ -1,5 +1,6 @@ # shows tracks for the given artist +from __future__ import print_function import spotipy import sys sp = spotipy.Spotify() @@ -8,5 +9,4 @@ if len(sys.argv) > 1: artist_name = ' '.join(sys.argv[1:]) tracks = sp.search(q=artist_name, limit=20) for i, t in enumerate(tracks['tracks']): - print ' ', i, t['name'] - + print(' ', i, t['name'])