Enable Score broadcast
N1MM has this feature to broadcast many information via UDP datagrams.
Requirements
N1MM has this feature to broadcast many information via UDP datagrams.
#!/usr/bin/python
## Added try / except to prevent app crashes
import socket
import json
import xmltodict
port = 7016
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", port))
print("waiting on port:", port)
while 1:
data, addr = s.recvfrom(1024)
data_dict = xmltodict.parse(data)
json_data=json.dumps(data_dict)
f = open("score.json", "w")
f.write(json_data)
f.close()
with open("score.json", "r") as f:
try:
data = json.load(f)
qso=int(data['dynamicresults']['breakdown']['qso'][1]['#text'])
multi=int(data['dynamicresults']['breakdown']['mult'][2]['#text'])
pts=int(data['dynamicresults']['breakdown']['point'][1]['#text'])
score=int(data['dynamicresults']['score'])
print("QSO "+str(qso))
print("Multi "+str(multi))
print("Points "+str(pts))
print("Score = "+str(score))
d=open("/var/www/yo8rxp.com/web/json1", "w")
d.write( '{\n"qso":' + str(qso) + ",\n" + '"mult":' + str(multi) + ",\n" + '"score":' + str(score) + ",\n" +'"pts":' + str(pts) + "\n}" )
except:
print ("error")