mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +00:00
pyflakes and some pep8
This commit is contained in:
parent
8a3ccd8b2a
commit
6e8ae44c5a
6
setup.py
6
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'],)
|
||||
|
21
spotipy.py
21
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
|
||||
'''
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user