Fixes index out of bounds bug and adds global placeholder variable

This commit is contained in:
Lloyd Owen
2021-01-28 19:15:14 +01:00
committed by Andrew Novac
parent 872e6f7455
commit cc2572c573

View File

@@ -12,10 +12,10 @@ load_dotenv(find_dotenv())
# Spotify scopes: # Spotify scopes:
# user-read-currently-playing # user-read-currently-playing
# user-read-recently-played # user-read-recently-played
PLACEHOLDER_IMAGE = "PLACEHOLER_BASE64_IMAGE_HERE"
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID") SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID") SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID")
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN") SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN")
REFRESH_TOKEN_URL = "https://accounts.spotify.com/api/token" REFRESH_TOKEN_URL = "https://accounts.spotify.com/api/token"
NOW_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing" NOW_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing"
RECENTLY_PLAYING_URL = ( RECENTLY_PLAYING_URL = (
@@ -102,7 +102,12 @@ def makeSVG(data):
else: else:
item = data["item"] item = data["item"]
currentStatus = "Vibing to:" currentStatus = "Vibing to:"
image = loadImageB64(item["album"]["images"][1]["url"])
if item["album"]["images"] == []:
image = PLACEHOLDER_IMAGE
else :
image = loadImageB64(item["album"]["images"][1]["url"])
artistName = item["artists"][0]["name"].replace("&", "&") artistName = item["artists"][0]["name"].replace("&", "&")
songName = item["name"].replace("&", "&") songName = item["name"].replace("&", "&")