diff --git a/site/app.py b/site/app.py index 4857d1e..20f728a 100644 --- a/site/app.py +++ b/site/app.py @@ -45,15 +45,18 @@ def increment_visitor_count(): @app.route('/') def index(): increment_visitor_count() - data = requests.get(apiRoot + "/1/user/" + user + "/playing-now") - if not data.json()['payload']['listens']: - nowPlaying = False - nowPlayingString = "nothing is playing right now." - else: - track = data.json()['payload']['listens'][0]['track_metadata']['track_name'] - artist = data.json()['payload']['listens'][0]['track_metadata']['artist_name'] - album = data.json()['payload']['listens'][0]['track_metadata']['release_name'] - nowPlayingString = f"now playing for {user}: {track} by {artist} from {album}" + try: + data = requests.get(apiRoot + "/1/user/" + user + "/playing-now") + if not data.json()['payload']['listens']: + nowPlaying = False + nowPlayingString = "nothing is playing right now." + else: + track = data.json()['payload']['listens'][0]['track_metadata']['track_name'] + artist = data.json()['payload']['listens'][0]['track_metadata']['artist_name'] + album = data.json()['payload']['listens'][0]['track_metadata']['release_name'] + nowPlayingString = f"now playing for {user}: {track} by {artist} from {album}" + except: + nowPlayingString = Failed to reach API return render_template('index.j2', np=nowPlayingString, visitor=get_visitor_count(), buttons=buttons, nyxbuttons=nyxbuttons)