pyBMNotify/pyBMNotify.py
Michael Clemens b821efb785 bug fix
2020-12-07 19:08:34 +01:00

35 lines
969 B
Python

from socketIO_client import SocketIO
import json
import datetime as dt
tg = [91, 98002]
id = ""
def on_connect():
print('connect')
def on_disconnect():
print('disconnect')
def on_reconnect():
print('reconnect')
def on_mqtt(*args):
out = ""
global id
call = json.loads(args[0]['payload'])
if call["DestinationID"] in tg and id != call["_id"]:
time = dt.datetime.utcfromtimestamp(call["Start"]).strftime("%Y/%m/%d %H:%M")
out += call["SourceCall"] + ' (' + call["SourceName"] + ') was active on ' + str(call["DestinationID"]) + ' (' + call["DestinationName"] + ') at ' + time
print(out)
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
id = call["_id"]
socket = SocketIO('https://api.brandmeister.network/lh')
socket.on('connect', on_connect)
socket.on('disconnect', on_disconnect)
socket.on('reconnect', on_reconnect)
socket.on('mqtt', on_mqtt)
socket.wait()