31 lines
1.0 KiB
Python
Executable File
31 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
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')
|
|
def on_close(ws, *error):
|
|
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() |