added notifications

added freepbx integration as notification source
This commit is contained in:
Brandon4466
2023-08-11 02:17:41 -07:00
parent 0039308633
commit 4467115135
9 changed files with 91 additions and 23 deletions

2
.cache
View File

@@ -1 +1 @@
{"access_token": "BQALcKusPjd5akQ3U_q5i2tQANIonOR6yv-Ec9WtGBjeip5n22b82jJQRzLHhDxQI8bztKCyuqHmiiY_gA3NUqANrbqZ2ei5cG1DySXnsMIQePD__mvGikehGbfBPHJkmKTTMk2xx56jiN9Xrg2JAtjSnTxckhgT5xqxyKbpZBvQIKEsX14VIDeGgA0ZvRxmrA9n0y67bWer5Lr411k", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1686382188, "refresh_token": "AQAby3zEGc-H8o8zciCRMZm-O6Gj3FAup6Vb0sRrbtiO48VyMTJMzU4DoJ_wrhk8LmOiN8Hvt0Fb_Ag-09XVEDgQe3VUBDD3HdoMk6aZA1n02VLygxQNMNUQgAGw6oUUdI0"}
{"access_token": "BQDochOG-kBM3GV43moO6zgHlLbsleUy9lT5bYHi1bMBm621i-8AMWUjRDimSFAC2bUaRbh-Qv-5DA2DwwT8_hfT93s6CB1kivAESd8q7teETG2wfFFfWSv-bKvyZu5FNvDK8ofekKNy-pYwiKxeUhYuqnpMB2l0-R1ysKkkUgeqiAH3bIXrCn2HaZeya7_zrbA5uN97R38BaE22DIE", "token_type": "Bearer", "expires_in": 3600, "scope": "user-library-modify user-library-read user-modify-playback-state user-read-playback-state", "expires_at": 1689301138, "refresh_token": "AQAby3zEGc-H8o8zciCRMZm-O6Gj3FAup6Vb0sRrbtiO48VyMTJMzU4DoJ_wrhk8LmOiN8Hvt0Fb_Ag-09XVEDgQe3VUBDD3HdoMk6aZA1n02VLygxQNMNUQgAGw6oUUdI0"}

View File

@@ -7,11 +7,11 @@ Control Spotify remotely with a nice and functional touchscreen interface
## Running
- Get a Spotify API Client ID and Secret from the [Spotify Developer Dashboard](https://developer.spotify.com/). Put these in the config.json file.
- Clone the repository
- Install required dependencies
```sh
pip install -r requirements.txt
```
- Configure the env variables
- Run
```sh
python spotifycontroller.py
```

30
_notify.py Normal file
View File

@@ -0,0 +1,30 @@
import tkinter as ttk
from tkinter import ttk as tk
from tkinter import PhotoImage
import os
import sv_ttk
def draw(cid, num, img, title="Notification"):
root = ttk.Tk()
root.title(title)
root.geometry("1280x50")
root.attributes("-topmost", True)
if os.name == 'posix':
root.overrideredirect(1)
try:
sv_ttk.use_dark_theme()
except:
pass
phone = PhotoImage(file=img)
phone_image = tk.Label(root, image=phone)
cid_label = tk.Label(root, text=cid, font=("Arial", 32))
num_label = tk.Label(root, text=num, font=("Arial", 32))
phone_image.grid(row=0, column=0, padx=10)
cid_label.grid(row=0, column=1, padx=10)
num_label.grid(row=0, column=2, padx=10)
root.after(15000, lambda: root.destroy())
root.mainloop()

24
freepbx.py Normal file
View File

@@ -0,0 +1,24 @@
from flask import Flask, request
import threading
from _notify import draw
app = Flask(__name__)
@app.route('/hook', methods=['GET'])
def wait_for_call():
# Get information from URL variables
num = request.args.get('num')
cid = request.args.get('CID')
img = "phone.png"
# Process the received information (you can customize this part)
print(f"Received param1: {num}")
print(f"Received param2: {cid}")
# Add more processing logic as needed
threading.Thread(target=draw, args=(cid, num, img)).start()
# Respond to the webhook request (optional)
return 'Webhook received successfully!', 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

BIN
phone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
phone_orig.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -210,6 +210,7 @@ def get_devices():
# unloadDevices_list()
# loadSleep()
# root.after(3600, get_devices)
try:
if spotify.current_playback() != None:
count = 0
# unloadSearching_Devices()
@@ -230,6 +231,8 @@ def get_devices():
# exec(f'dev_{num_of_device}.grid(row={num_of_device}, column=1)')
devices_list.insert(num_of_device, list_of_devices["devices"][num_of_device]["name"])
root.after(8500, get_devices)
except:
root.after(5000, get_devices)
# def wakeup():
# global count
@@ -563,6 +566,7 @@ def unloadNow_playing():
song_label.grid_forget()
previous_button.grid_forget()
play_button.grid_forget()
pause_button.grid_forget()
next_button.grid_forget()
progress_bar.grid_forget()
lyrics_label.grid_forget()

View File

@@ -6,7 +6,8 @@ from time import sleep
import subprocess
from pynput import mouse
from functools import partial
from os import name, path, remove, system
from os import name, path, remove, system, kill, popen
import signal
# while True:
@@ -53,7 +54,16 @@ while True:
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:

BIN
update.zip Normal file

Binary file not shown.