2023-01-26 19:40:26 -08:00
|
|
|
import websocket
|
|
|
|
import os
|
|
|
|
from playsound import playsound
|
|
|
|
from generate_config import generate_config
|
|
|
|
import json
|
|
|
|
|
|
|
|
parent = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join(parent, 'config.json')):
|
|
|
|
generate_config("Wardyn's feditools", "read write follow push")
|
|
|
|
with open(os.path.join(parent, 'config.json'), 'r') as config_file:
|
|
|
|
config = json.load(config_file)
|
|
|
|
|
|
|
|
sound = os.path.join(parent, 'notification.mp3')
|
|
|
|
|
|
|
|
def on_message(ws, message):
|
|
|
|
print('Received notification')
|
|
|
|
playsound(sound)
|
|
|
|
def on_open(ws):
|
|
|
|
print('Websocket opened')
|
2023-01-29 16:09:37 -08:00
|
|
|
def on_close(ws, *error):
|
2023-01-26 19:40:26 -08:00
|
|
|
print('Websocket closed, attempting to reconnect')
|
|
|
|
connect_websocket()
|
|
|
|
|
|
|
|
def connect_websocket():
|
|
|
|
ws = websocket.WebSocketApp("wss://" + config['instance'].split('/')[-1] + "/api/v1/streaming?access_token=" + config['user_token'] + "&stream=user:notification",
|
|
|
|
on_message = on_message, on_open = on_open, on_close = on_close, on_error=on_close)
|
|
|
|
ws.run_forever()
|
|
|
|
|
|
|
|
connect_websocket()
|