Merge pull request #1 from hugovk/master

CI and stuff
This commit is contained in:
Paul Lamere 2014-04-06 18:18:19 -04:00
commit 2f36e11277
8 changed files with 104 additions and 28 deletions

54
.gitignore vendored Normal file
View File

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

29
.travis.yml Normal file
View File

@ -0,0 +1,29 @@
language: python
python:
- 2.6
- 2.7
- 3.2
- 3.3
- 3.4
- pypy
install:
- pip install coveralls
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
- coveralls
- pip install pep8 pyflakes
- pep8 *.py tests/*.py
- pyflakes *.py tests/*.py
matrix:
allow_failures:
- python: 3.2
- python: 3.4

View File

@ -9,8 +9,6 @@ if len(sys.argv) > 1:
else: else:
urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu' urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
sp = spotipy.Spotify() sp = spotipy.Spotify()
artist = sp.artist(urn) artist = sp.artist(urn)
pprint.pprint(artist) pprint.pprint(artist)

View File

@ -12,4 +12,3 @@ else:
sp = spotipy.Spotify() sp = spotipy.Spotify()
track = sp.track(urn) track = sp.track(urn)
pprint.pprint(track) pprint.pprint(track)

View File

@ -1,5 +1,6 @@
# shows tracks for the given artist # shows tracks for the given artist
from __future__ import print_function
import spotipy import spotipy
import sys import sys
sp = spotipy.Spotify() sp = spotipy.Spotify()
@ -8,5 +9,4 @@ if len(sys.argv) > 1:
artist_name = ' '.join(sys.argv[1:]) artist_name = ' '.join(sys.argv[1:])
tracks = sp.search(q=artist_name, limit=20) tracks = sp.search(q=artist_name, limit=20)
for i, t in enumerate(tracks['tracks']): for i, t in enumerate(tracks['tracks']):
print ' ', i, t['name'] print(' ', i, t['name'])

View File

@ -4,9 +4,9 @@ from setuptools import setup
setup( setup(
name='spotipy', name='spotipy',
version='0.9', version='0.9',
description='simple client for The Spotify Web API', description='simple client for the Spotify Web API',
author="@plamere", author="@plamere",
author_email="paul@echonest.com", author_email="paul@echonest.com",
url='http://github.com/plamere/spotipy', url='http://github.com/plamere/spotipy',
install_requires=['requests>=1.0',], install_requires=['requests>=1.0', ],
py_modules=['spotipy'],) py_modules=['spotipy'],)

View File

@ -1,20 +1,19 @@
import requests 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): class SpotifyException(Exception):
def __init__(self, http_status, code, msg): def __init__(self, http_status, code, msg):
self.http_status = http_status self.http_status = http_status
self.code = code self.code = code
self.msg = msg self.msg = msg
def __str__(self): 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): class Spotify(object):
def __init__(self): def __init__(self):
@ -30,17 +29,16 @@ class Spotify(object):
raise SpotifyException(r.status_code, -1, u'the requested resource could not be found') raise SpotifyException(r.status_code, -1, u'the requested resource could not be found')
return r.json() return r.json()
def get(self, method, args=None, **kwargs):
def get(self, method, args = None, **kwargs):
if args: if args:
kwargs.update(args) kwargs.update(args)
return self._internal_call('GET', method, kwargs) return self._internal_call('GET', method, kwargs)
def _error(self, msg): def _error(self, msg):
print('ERROR - ' + msg); print('ERROR - ' + msg)
def _warn(self, msg): def _warn(self, msg):
print('warning:' + msg); print('warning:' + msg)
def track(self, track_id): def track(self, track_id):
''' returns a single track given the track's ID, URN or URL ''' 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] tlist = [self._get_id('album', a) for a in albums]
return self.get('albums/?ids=' + ','.join(tlist)) return self.get('albums/?ids=' + ','.join(tlist))
def search(self, q, limit=10, offset=0, type='track'): def search(self, q, limit=10, offset=0, type='track'):
''' searches for an item ''' searches for an item
''' '''

View File

@ -1,9 +1,7 @@
# -*- coding: latin-1 -*- # -*- coding: latin-1 -*-
import spotipy import spotipy
import unittest import unittest
import pprint
import logging
class TestSpotipy(unittest.TestCase): class TestSpotipy(unittest.TestCase):
@ -84,5 +82,6 @@ class TestSpotipy(unittest.TestCase):
self.assertTrue(False) self.assertTrue(False)
except spotipy.SpotifyException: except spotipy.SpotifyException:
self.assertTrue(True) self.assertTrue(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()