Skip to content

Commit

Permalink
went through the files again, additions from #1165 are also included
Browse files Browse the repository at this point in the history
  • Loading branch information
dieser-niko authored Dec 3, 2024
1 parent 51c22c1 commit 61bd0f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
7 changes: 2 additions & 5 deletions examples/artist_albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def get_args():
def get_artist(name):
results = sp.search(q='artist:' + name, type='artist')
items = results['artists']['items']
if len(items) > 0:
return items[0]
else:
return None
return items[0] if items else None


def show_artist_albums(artist):
Expand All @@ -38,7 +35,7 @@ def show_artist_albums(artist):
for album in albums:
name = album['name']
if name not in seen:
logger.info('ALBUM: {name}')
logger.info(f'ALBUM: {name}')
seen.add(name)


Expand Down
5 changes: 1 addition & 4 deletions examples/artist_discography.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def get_args():
def get_artist(name):
results = sp.search(q='artist:' + name, type='artist')
items = results['artists']['items']
if len(items) > 0:
return items[0]
else:
return None
return items[0] if items else None


def show_album_tracks(album):
Expand Down
5 changes: 1 addition & 4 deletions examples/artist_recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def get_args():
def get_artist(name):
results = sp.search(q='artist:' + name, type='artist')
items = results['artists']['items']
if len(items) > 0:
return items[0]
else:
return None
return items[0] if items else None


def show_recommendations_for_artist(artist):
Expand Down
11 changes: 3 additions & 8 deletions examples/follow_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ def get_args():

def main():
args = get_args()

if args.playlist is None:
# Uses the Spotify Global Top 50 playlist
spotipy.Spotify(auth_manager=SpotifyOAuth()).current_user_follow_playlist(
'37i9dQZEVXbMDoHDwVN2tF')

else:
spotipy.Spotify(auth_manager=SpotifyOAuth()).current_user_follow_playlist(args.playlist)
# Uses Lofi Girl playlist
playlist = args.playlist or '0vvXsWCC9xrXsKd4FyS8kM'
spotipy.Spotify(auth_manager=SpotifyOAuth()).current_user_follow_playlist(playlist)


if __name__ == '__main__':
Expand Down
12 changes: 6 additions & 6 deletions spotipy/cache_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def save_token_to_cache(self, token_info):
try:
self.request.session['token_info'] = token_info
except Exception as e:
logger.warning("Error saving token to cache: " + str(e))
logger.warning(f"Error saving token to cache: {e}")


class FlaskSessionCacheHandler(CacheHandler):
Expand All @@ -173,7 +173,7 @@ def save_token_to_cache(self, token_info):
try:
self.session["token_info"] = token_info
except Exception as e:
logger.warning("Error saving token to cache: " + str(e))
logger.warning(f"Error saving token to cache: {e}")


class RedisCacheHandler(CacheHandler):
Expand All @@ -199,15 +199,15 @@ def get_cached_token(self):
if token_info:
return json.loads(token_info)
except RedisError as e:
logger.warning('Error getting token from cache: ' + str(e))
logger.warning(f"Error getting token from cache: {e}")

return token_info

def save_token_to_cache(self, token_info):
try:
self.redis.set(self.key, json.dumps(token_info))
except RedisError as e:
logger.warning('Error saving token to cache: ' + str(e))
logger.warning(f"Error saving token to cache: {e}")


class MemcacheCacheHandler(CacheHandler):
Expand All @@ -231,11 +231,11 @@ def get_cached_token(self):
if token_info:
return json.loads(token_info.decode())
except MemcacheError as e:
logger.warning('Error getting token from cache' + str(e))
logger.warning(f"Error getting token to cache: {e}")

def save_token_to_cache(self, token_info):
from pymemcache import MemcacheError
try:
self.memcache.set(self.key, json.dumps(token_info))
except MemcacheError as e:
logger.warning('Error saving token to cache' + str(e))
logger.warning(f"Error saving token to cache: {e}")
10 changes: 5 additions & 5 deletions spotipy/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _request_access_token(self):
)

logger.debug(
"sending POST request to {} with Headers: {} and Body: {!r}".format(
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
self.OAUTH_TOKEN_URL, headers, payload)
)

Expand Down Expand Up @@ -532,7 +532,7 @@ def get_access_token(self, code=None, as_dict=True, check_cache=True):
headers = self._make_authorization_headers()

logger.debug(
"sending POST request to {} with Headers: {} and Body: {!r}".format(
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
self.OAUTH_TOKEN_URL, headers, payload)
)

Expand Down Expand Up @@ -562,7 +562,7 @@ def refresh_access_token(self, refresh_token):
headers = self._make_authorization_headers()

logger.debug(
"sending POST request to {} with Headers: {} and Body: {!r}".format(
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
self.OAUTH_TOKEN_URL, headers, payload)
)

Expand Down Expand Up @@ -888,7 +888,7 @@ def get_access_token(self, code=None, check_cache=True):
headers = {"Content-Type": "application/x-www-form-urlencoded"}

logger.debug(
"sending POST request to {} with Headers: {} and Body: {!r}".format(
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
self.OAUTH_TOKEN_URL, headers, payload)
)

Expand Down Expand Up @@ -919,7 +919,7 @@ def refresh_access_token(self, refresh_token):
headers = {"Content-Type": "application/x-www-form-urlencoded"}

logger.debug(
"sending POST request to {} with Headers: {} and Body: {!r}".format(
"Sending POST request to {} with Headers: {} and Body: {!r}".format(
self.OAUTH_TOKEN_URL, headers, payload)
)

Expand Down

0 comments on commit 61bd0f9

Please sign in to comment.