code fixes

This commit is contained in:
Michael Clemens 2020-12-07 19:26:13 +01:00
parent b821efb785
commit 5c975d58ea
1 changed files with 13 additions and 7 deletions

View File

@ -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)