From d4a72c8befbb58a283705b4bc9367855e243563b Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:57:01 +0100 Subject: [PATCH] ups, forgot stats.py --- tnc/stats.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tnc/stats.py diff --git a/tnc/stats.py b/tnc/stats.py new file mode 100644 index 00000000..60132833 --- /dev/null +++ b/tnc/stats.py @@ -0,0 +1,69 @@ +# -*- coding: UTF-8 -*- +""" +Created on 05.11.23 + +@author: DJ2LS +""" +# pylint: disable=invalid-name, line-too-long, c-extension-no-member +# pylint: disable=import-outside-toplevel, attribute-defined-outside-init + +import requests +import threading +import time +import ujson as json +import structlog +import static + +log = structlog.get_logger("stats") + + +class stats(): + def __init__(self): + self.explorer_url = "https://api.freedata.app/stats.php" + def push(self): + """ + $callsign = $json["callsign"]; + $dxcallsign = $json["dxcallsign"]; + $gridsquare = $json["gridsquare"]; + $dxgridsquare = $json["dxgridsquare"]; + $frequency = $json["frequency"]; + $avgstrength = $json["avgstrength"]; + $avgsnr = $json["avgsnr"]; + $bytesperminute = $json["bytesperminute"]; + $filesize = $json["filesize"]; + $compressionfactor = $json["compressionfactor"]; + $nacks = $json["nacks"]; + $crcerror = $json["crcerror"]; + $duration = $json["duration"]; + $version = $json["version"]; + """ + + headers = {"Content-Type": "application/json"} + station_data = { + 'callsign': str(static.MYCALLSIGN, "utf-8"), + 'dxcallsign': str(static.DXCALLSIGN, "utf-8"), + 'gridsquare': str(static.MYGRID, "utf-8"), + 'dxgridsquare': str(static.DXGRID, "utf-8"), + 'frequency': 0 if static.HAMLIB_FREQUENCY is None else static.HAMLIB_FREQUENCY, + 'avgstrength': 0, + 'avgsnr': 0, + 'bytesperminute': str(static.ARQ_BYTES_PER_MINUTE, "utf-8"), + 'filesize': str(static.TOTAL_BYTES, "utf-8"), + 'compressionfactor': str(static.ARQ_COMPRESSION_FACTOR, "utf-8"), + 'nacks': 0, + 'crcerror': 0, + 'duration': 0, + 'percentage': 0, + 'version': str(static.VERSION, "utf-8") + } + + station_data = json.dumps(station_data) + try: + response = requests.post(self.explorer_url, json=station_data, headers=headers) + log.info("[STATS] push", code=response.status_code) + + # print(response.status_code) + # print(response.content) + + except Exception as e: + log.warning("[EXPLORER] connection lost")