import urllib from urllib.request import urlopen from zipfile import ZipFile from io import BytesIO from time import sleep import subprocess from pynput import mouse from functools import partial from os import name, path, remove, system # while True: # try: # urlopen('http://bbrunson.com', timeout=1) # print("Connection to server established.") # break # except: # pass if name == 'nt': print("Windows detected. Shutting down...") exit() # 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 def click(x, y, button, pressed, foo): return False bar = partial(click, foo="bar", button=True, pressed=True) while True: try: urlopen('http://bbrunson.com', timeout=1) print("Connection to server established.") try: if path.exists('web/update/update.zip'): print("Update found. Installing...") with ZipFile('web/update/update.zip') as zipObj: zipObj.extractall() remove('web/update/update.zip') print("Uploaded update successfully installed.") print("Checking for updates...") with ZipFile(BytesIO((urlopen('http://files.bbrunson.com/spotify-gui/update.zip')).read())) as zipObj: zipObj.extractall() print("Update successfully downloaded and installed.") except urllib.error.HTTPError: print("No update available.") pass subprocess.Popen(['python3', 'web/web.py']) subprocess.check_call(['python3', 'spotifycontroller.py']) except Exception as e: if e.args[0] == 1: print("Program has requested sleep mode.") system("xset -display :0 s 30") with mouse.Listener(on_move=bar, on_click=bar, on_scroll=bar) as listener: listener.join() else: print(e) print("Restart procedure initiated: Checking server connection, checking for update, and then reestablishing the application in 10 seconds.") sleep(10) continue