pyBMNotify/pyBMNotify.py

41 lines
1.3 KiB
Python
Raw Normal View History

2020-12-07 17:00:49 +00:00
from socketIO_client import SocketIO
import json
2020-12-07 18:02:56 +00:00
import datetime as dt
2020-12-07 17:00:49 +00:00
2020-12-07 18:08:34 +00:00
tg = [91, 98002]
2020-12-07 18:26:13 +00:00
min_duration = 2
2020-12-07 18:02:56 +00:00
id = ""
2020-12-07 17:00:49 +00:00
def on_connect():
print('connect')
def on_disconnect():
print('disconnect')
def on_reconnect():
print('reconnect')
def on_mqtt(*args):
out = ""
2020-12-07 18:02:56 +00:00
global id
2020-12-07 17:00:49 +00:00
call = json.loads(args[0]['payload'])
2020-12-07 18:26:13 +00:00
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
#if call["DestinationID"] in tg and id != call["SessionID"]:
if call["DestinationID"] in tg and call["Stop"] > 0 and id != call["SessionID"]:
duration = call["Stop"] - call["Start"]
if duration > min_duration:
time = dt.datetime.utcfromtimestamp(call["Start"]).strftime("%Y/%m/%d %H:%M")
out += call["SourceCall"] + ' (' + call["SourceName"] + ') was active on '
out += str(call["DestinationID"]) + ' (' + call["DestinationName"] + ') at '
out += time + ' (' + str(duration) + ' seconds)'
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
id = call["SessionID"]
print(out)
2020-12-07 17:00:49 +00:00
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()