From 0eeeeb4a50f8c03c2bdbe3298c540131ca7b118d Mon Sep 17 00:00:00 2001 From: "Sebastien (Work)" Date: Mon, 23 Oct 2017 22:50:05 +0100 Subject: [PATCH 1/3] Remove unused imports All imported modules that were note used in examples have been removed. --- examples/add_tracks_to_playlist.py | 1 - examples/create_playlist.py | 2 -- examples/errors.py | 3 --- examples/my_playlists.py | 2 -- examples/show_artist_top_tracks.py | 1 - examples/show_featured_playlists.py | 1 - examples/show_new_releases.py | 1 - examples/show_related.py | 1 - examples/user_playlists.py | 3 --- 9 files changed, 15 deletions(-) diff --git a/examples/add_tracks_to_playlist.py b/examples/add_tracks_to_playlist.py index a5297da..d0df161 100644 --- a/examples/add_tracks_to_playlist.py +++ b/examples/add_tracks_to_playlist.py @@ -1,7 +1,6 @@ # Adds tracks to a playlist -import pprint import sys import spotipy diff --git a/examples/create_playlist.py b/examples/create_playlist.py index efa334d..6cad834 100644 --- a/examples/create_playlist.py +++ b/examples/create_playlist.py @@ -2,8 +2,6 @@ import pprint import sys -import os -import subprocess import spotipy import spotipy.util as util diff --git a/examples/errors.py b/examples/errors.py index 570600f..36bcaf9 100644 --- a/examples/errors.py +++ b/examples/errors.py @@ -2,10 +2,7 @@ from __future__ import print_function # (at top of module) from spotipy.oauth2 import SpotifyClientCredentials -import json import spotipy -import time -import sys client_credentials_manager = SpotifyClientCredentials() diff --git a/examples/my_playlists.py b/examples/my_playlists.py index 58e02df..a48fb0f 100644 --- a/examples/my_playlists.py +++ b/examples/my_playlists.py @@ -1,11 +1,9 @@ # Shows the top artists for a user -import pprint import sys import spotipy import spotipy.util as util -import simplejson as json if len(sys.argv) > 1: username = sys.argv[1] diff --git a/examples/show_artist_top_tracks.py b/examples/show_artist_top_tracks.py index a80beb8..34b5a34 100644 --- a/examples/show_artist_top_tracks.py +++ b/examples/show_artist_top_tracks.py @@ -2,7 +2,6 @@ import spotipy import sys -import pprint if len(sys.argv) > 1: urn = sys.argv[1] diff --git a/examples/show_featured_playlists.py b/examples/show_featured_playlists.py index 2c7f8d9..769037c 100644 --- a/examples/show_featured_playlists.py +++ b/examples/show_featured_playlists.py @@ -2,7 +2,6 @@ import spotipy import sys -import pprint import spotipy.util as util if len(sys.argv) > 1: diff --git a/examples/show_new_releases.py b/examples/show_new_releases.py index 5205245..c728eee 100644 --- a/examples/show_new_releases.py +++ b/examples/show_new_releases.py @@ -2,7 +2,6 @@ import spotipy import sys -import pprint import spotipy.util as util if len(sys.argv) > 1: diff --git a/examples/show_related.py b/examples/show_related.py index b78e1dc..15b3c3d 100644 --- a/examples/show_related.py +++ b/examples/show_related.py @@ -3,7 +3,6 @@ import spotipy import sys -import pprint if len(sys.argv) > 1: artist_name = sys.argv[1] diff --git a/examples/user_playlists.py b/examples/user_playlists.py index 7bcc1f5..e94e810 100644 --- a/examples/user_playlists.py +++ b/examples/user_playlists.py @@ -1,9 +1,6 @@ # shows a user's playlists (need to be authenticated via oauth) -import pprint import sys -import os -import subprocess import spotipy From 0b0942423ce98a4662966483f9f14c15323a010d Mon Sep 17 00:00:00 2001 From: "Sebastien (Work)" Date: Mon, 23 Oct 2017 22:53:20 +0100 Subject: [PATCH 2/3] Remove spaces around keyword operator remove space around operator '=' for keywords. --- examples/artist_recommendations.py | 2 +- examples/title_chain.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/artist_recommendations.py b/examples/artist_recommendations.py index 6efbc1e..142cf49 100644 --- a/examples/artist_recommendations.py +++ b/examples/artist_recommendations.py @@ -19,7 +19,7 @@ def get_artist(name): def show_recommendations_for_artist(artist): albums = [] - results = sp.recommendations(seed_artists = [artist['id']]) + results = sp.recommendations(seed_artists=[artist['id']]) for track in results['tracks']: print track['name'], '-', track['artists'][0]['name'] diff --git a/examples/title_chain.py b/examples/title_chain.py index 67a55c0..ac74fe5 100644 --- a/examples/title_chain.py +++ b/examples/title_chain.py @@ -21,7 +21,7 @@ def find_songs_that_start_with_word(word): out = [] while offset < max_offset and len(out) < max_titles: - results = sp.search(q=word, type = 'track', limit=50, offset = offset) + results = sp.search(q=word, type='track', limit=50, offset=offset) if len(results['tracks']['items']) == 0: break From 6c83f09898393facc8f3276c74e3f972957a8c69 Mon Sep 17 00:00:00 2001 From: "Sebastien (Work)" Date: Mon, 23 Oct 2017 23:02:17 +0100 Subject: [PATCH 3/3] Format examples Add spaces after ':' and ','. Remove spaces before and after '(', '{', '[', ']', '}' and ')'. --- examples/artist_albums.py | 2 +- examples/audio_analysis_for_track.py | 2 +- examples/audio_features.py | 2 +- examples/audio_features_for_track.py | 2 +- examples/change_playlist_details.py | 2 +- examples/errors.py | 8 ++++---- examples/remove_specific_tracks_from_playlist.py | 4 ++-- examples/show_new_releases.py | 2 +- examples/user_starred_playlist.py | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/artist_albums.py b/examples/artist_albums.py index 6b9f6ce..4213985 100644 --- a/examples/artist_albums.py +++ b/examples/artist_albums.py @@ -20,7 +20,7 @@ def show_artist_albums(artist): results = sp.next(results) albums.extend(results['items']) seen = set() # to avoid dups - albums.sort(key=lambda album:album['name'].lower()) + albums.sort(key=lambda album: album['name'].lower()) for album in albums: name = album['name'] if name not in seen: diff --git a/examples/audio_analysis_for_track.py b/examples/audio_analysis_for_track.py index 39e8347..1f728a5 100644 --- a/examples/audio_analysis_for_track.py +++ b/examples/audio_analysis_for_track.py @@ -20,4 +20,4 @@ start = time.time() analysis = sp.audio_analysis(tid) delta = time.time() - start print(json.dumps(analysis, indent=4)) -print ("analysis retrieved in %.2f seconds" % (delta,)) +print("analysis retrieved in %.2f seconds" % (delta,)) diff --git a/examples/audio_features.py b/examples/audio_features.py index 079f4f9..989c852 100644 --- a/examples/audio_features.py +++ b/examples/audio_features.py @@ -33,4 +33,4 @@ for feature in features: analysis = sp._get(feature['analysis_url']) print(json.dumps(analysis, indent=4)) print() -print ("features retrieved in %.2f seconds" % (delta,)) +print("features retrieved in %.2f seconds" % (delta,)) diff --git a/examples/audio_features_for_track.py b/examples/audio_features_for_track.py index cdc980a..0565298 100644 --- a/examples/audio_features_for_track.py +++ b/examples/audio_features_for_track.py @@ -22,4 +22,4 @@ if len(sys.argv) > 1: features = sp.audio_features(tids) delta = time.time() - start print(json.dumps(features, indent=4)) - print ("features retrieved in %.2f seconds" % (delta,)) + print("features retrieved in %.2f seconds" % (delta,)) diff --git a/examples/change_playlist_details.py b/examples/change_playlist_details.py index 621f5d0..42044aa 100644 --- a/examples/change_playlist_details.py +++ b/examples/change_playlist_details.py @@ -24,7 +24,7 @@ if len(sys.argv) > 3: description = sys.argv[6] else: - print ("Usage: %s username playlist_id name [public collaborative " + print("Usage: %s username playlist_id name [public collaborative " "description]" % (sys.argv[0])) sys.exit() diff --git a/examples/errors.py b/examples/errors.py index 36bcaf9..546fcb4 100644 --- a/examples/errors.py +++ b/examples/errors.py @@ -9,12 +9,12 @@ client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) sp.trace=True try: - print ('bad call 0') + print('bad call 0') bad_artist_call = sp.artist('spotify:artist:12341234') except spotipy.client.SpotifyException: - print ('bad call 0 exception' ) + print('bad call 0 exception') -print ('bad call 1') +print('bad call 1') bad_artist_call = sp.artist('spotify:artist:12341234') -print ('bad artist', bad_artist_call) +print('bad artist', bad_artist_call) diff --git a/examples/remove_specific_tracks_from_playlist.py b/examples/remove_specific_tracks_from_playlist.py index a99dc94..5821f0e 100644 --- a/examples/remove_specific_tracks_from_playlist.py +++ b/examples/remove_specific_tracks_from_playlist.py @@ -11,10 +11,10 @@ if len(sys.argv) > 3: username = sys.argv[1] playlist_id = sys.argv[2] track_ids_and_positions = sys.argv[3:] - track_ids = [ ] + track_ids = [] for t_pos in sys.argv[3:]: tid, pos = t_pos.split(',') - track_ids.append( { "uri" : tid, "positions": [ int(pos)] } ) + track_ids.append({"uri": tid, "positions": [int(pos)]}) else: print("Usage: %s username playlist_id track_id,pos track_id,pos ..." % (sys.argv[0],)) sys.exit() diff --git a/examples/show_new_releases.py b/examples/show_new_releases.py index c728eee..d4bd5fa 100644 --- a/examples/show_new_releases.py +++ b/examples/show_new_releases.py @@ -21,7 +21,7 @@ if token: while response: albums = response['albums'] for i, item in enumerate(albums['items']): - print(albums['offset'] + i,item['name']) + print(albums['offset'] + i, item['name']) if albums['next']: response = sp.next(albums) diff --git a/examples/user_starred_playlist.py b/examples/user_starred_playlist.py index 914344a..645384c 100644 --- a/examples/user_starred_playlist.py +++ b/examples/user_starred_playlist.py @@ -23,7 +23,7 @@ if token: while tracks: for item in tracks['items']: track = item['track'] - print(which, track['name' ], ' --', track['artists'][0]['name']) + print(which, track['name'], ' --', track['artists'][0]['name']) which += 1 tracks = sp.next(tracks)