Files
spotify-gui/update.py
Brandon4466 4467115135 added notifications
added freepbx integration as notification source
2023-08-11 02:17:41 -07:00

78 lines
2.7 KiB
Python

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, kill, popen
import signal
# 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
for line in popen("ps ax | grep " + "web.py" + " | grep -v grep"):
fields = line.split()
pid = fields[0]
kill(int(pid), signal.SIGKILL)
subprocess.Popen(['python3', 'web/web.py'])
for line in popen("ps ax | grep " + "freepbx.py" + " | grep -v grep"):
fields = line.split()
pid = fields[0]
kill(int(pid), signal.SIGKILL)
subprocess.Popen(['python3', 'freepbx.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