Changed update so it doesn't retry to fast
Refactored code
This commit is contained in:
14
update.py
14
update.py
@@ -2,24 +2,30 @@ 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
|
||||
from time import sleep
|
||||
|
||||
|
||||
while True:
|
||||
try:
|
||||
urlopen('http://bbrunson.com', timeout=1)
|
||||
print("Connection to server established.")
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
print("Checking for updates...")
|
||||
with ZipFile(BytesIO((urlopen('http://files.bbrunson.com/spotify-gui/update.zip')).read())) as zipObj:
|
||||
zipObj.extractall()
|
||||
print("Update successfully installed.")
|
||||
except urllib.error.HTTPError:
|
||||
print("No update available.")
|
||||
pass
|
||||
|
||||
try:
|
||||
exec(open('spotifycontroller.py').read())
|
||||
except (RequestsExceptions.HTTPError, SpotipyExceptions.SpotifyException):
|
||||
print("An error has ocurred, saving and reestablishing application now.")
|
||||
except:
|
||||
print("An error has ocurred, reestablishing the application in 10 seconds.")
|
||||
sleep(10)
|
||||
exec(open('spotifycontroller.py').read())
|
||||
Reference in New Issue
Block a user