From 5c975d58eaa37fe8bc3025b4001b09084d084f3f Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Mon, 7 Dec 2020 19:26:13 +0100 Subject: [PATCH] code fixes --- pyBMNotify.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pyBMNotify.py b/pyBMNotify.py index 3451893..7ac997e 100644 --- a/pyBMNotify.py +++ b/pyBMNotify.py @@ -3,6 +3,7 @@ import json import datetime as dt tg = [91, 98002] +min_duration = 2 id = "" def on_connect(): @@ -18,13 +19,18 @@ 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"] - + #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) socket = SocketIO('https://api.brandmeister.network/lh') socket.on('connect', on_connect)