fixed parameter encoding in stats

This commit is contained in:
DJ2LS 2023-02-03 13:30:42 +01:00
parent 1682c30456
commit cb3c5eb94e
2 changed files with 9 additions and 10 deletions

View file

@ -242,10 +242,7 @@ class radio:
if 'RPRT' not in alc: if 'RPRT' not in alc:
try: try:
alc = float(alc) alc = float(alc)
if alc != 0.0: self.alc = alc if alc != 0.0 else static.HAMLIB_ALC
self.alc = alc
else:
self.alc = static.HAMLIB_ALC
except ValueError: except ValueError:
self.alc = 0.0 self.alc = 0.0

View file

@ -20,6 +20,7 @@ log = structlog.get_logger("stats")
class stats(): class stats():
def __init__(self): def __init__(self):
self.explorer_url = "https://api.freedata.app/stats.php" self.explorer_url = "https://api.freedata.app/stats.php"
def push(self): def push(self):
""" """
$callsign = $json["callsign"]; $callsign = $json["callsign"];
@ -40,24 +41,25 @@ class stats():
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
station_data = { station_data = {
'callsign': str(static.MYCALLSIGN, "utf-8"), #'callsign': str(static.MYCALLSIGN, "utf-8"),
'dxcallsign': str(static.DXCALLSIGN, "utf-8"), #'dxcallsign': str(static.DXCALLSIGN, "utf-8"),
'gridsquare': str(static.MYGRID, "utf-8"), 'gridsquare': str(static.MYGRID, "utf-8"),
'dxgridsquare': str(static.DXGRID, "utf-8"), 'dxgridsquare': str(static.DXGRID, "utf-8"),
'frequency': 0 if static.HAMLIB_FREQUENCY is None else static.HAMLIB_FREQUENCY, 'frequency': 0 if static.HAMLIB_FREQUENCY is None else static.HAMLIB_FREQUENCY,
'avgstrength': 0, 'avgstrength': 0,
'avgsnr': 0, 'avgsnr': 0,
'bytesperminute': str(static.ARQ_BYTES_PER_MINUTE, "utf-8"), 'bytesperminute': static.ARQ_BYTES_PER_MINUTE,
'filesize': str(static.TOTAL_BYTES, "utf-8"), 'filesize': static.TOTAL_BYTES,
'compressionfactor': str(static.ARQ_COMPRESSION_FACTOR, "utf-8"), 'compressionfactor': static.ARQ_COMPRESSION_FACTOR,
'nacks': 0, 'nacks': 0,
'crcerror': 0, 'crcerror': 0,
'duration': 0, 'duration': 0,
'percentage': 0, 'percentage': 0,
'version': str(static.VERSION, "utf-8") 'version': static.VERSION
} }
station_data = json.dumps(station_data) station_data = json.dumps(station_data)
print(station_data)
try: try:
response = requests.post(self.explorer_url, json=station_data, headers=headers) response = requests.post(self.explorer_url, json=station_data, headers=headers)
log.info("[STATS] push", code=response.status_code) log.info("[STATS] push", code=response.status_code)