import urllib from urllib.request import urlopen from zipfile import ZipFile from io import BytesIO from spotipy import exceptions as SpotipyExceptions from requests import exceptions as RequestsExceptions while True: try: urlopen('http://bbrunson.com', timeout=1) break except: pass try: with ZipFile(BytesIO((urlopen('http://files.bbrunson.com/spotify-gui/update.zip')).read())) as zipObj: zipObj.extractall() except urllib.error.HTTPError: pass try: exec(open('spotifycontroller.py').read()) except (RequestsExceptions.HTTPError, SpotipyExceptions.SpotifyException): print("An error has ocurred, saving and reestablishing application now.") exec(open('spotifycontroller.py').read())