pyBMNotify/pyBMNotify.py

35 lines
910 B
Python
Raw Normal View History

2020-12-07 18:00:49 +01:00
from socketIO_client import SocketIO
import json
2020-12-07 19:02:56 +01:00
import datetime as dt
2020-12-07 18:00:49 +01:00
2020-12-07 19:02:56 +01:00
tg = 31650
id = ""
2020-12-07 18:00:49 +01:00
def on_connect():
print('connect')
def on_disconnect():
print('disconnect')
def on_reconnect():
print('reconnect')
def on_mqtt(*args):
out = ""
2020-12-07 19:02:56 +01:00
global id
2020-12-07 18:00:49 +01:00
call = json.loads(args[0]['payload'])
2020-12-07 19:02:56 +01:00
if call["DestinationID"] == 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(tg) + ' at ' + time
2020-12-07 18:00:49 +01:00
print(out)
2020-12-07 19:02:56 +01:00
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
id = call["_id"]
2020-12-07 18:00:49 +01: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()