From bfb968fc4f0391cfb54e72efdbf90568df4835fd Mon Sep 17 00:00:00 2001 From: iou1name Date: Thu, 12 Sep 2019 21:05:25 -0400 Subject: [PATCH] tracker stats table periodically --- events.py | 6 ++++++ static/aberrant.js | 22 ++++++++++++++++++++-- templates/index.html | 8 ++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/events.py b/events.py index e706ea5..b194d54 100644 --- a/events.py +++ b/events.py @@ -12,6 +12,12 @@ async def active_torrents(ws, data): res = {'event': 'active_torrents', 'data': data} await ws.send_json(res) +async def tracker_stats(ws, data): + """Returns tracker stats.""" + data = rtorrent.get_stats() + res = {'event': 'tracker_stats', 'data': data} + await ws.send_json(res) + events = {} for obj in dir(): if type(locals()[obj]) == types.FunctionType: diff --git a/static/aberrant.js b/static/aberrant.js index 01ec709..377e882 100644 --- a/static/aberrant.js +++ b/static/aberrant.js @@ -1,6 +1,6 @@ function load() { //let intervalID = window.setInterval(get_active_torrents_ajax, 20000); - let intervalID = window.setInterval(get_active_torrents, 5000); + let intervalID = window.setInterval(update, 5000); } function get_active_torrents_ajax() { @@ -65,7 +65,19 @@ socket.events['active_torrents'] = function(data) { }); } socket.events['tracker_stats'] = function(data) { - console.log(data); + let table = document.querySelector('#tracker_stats tbody'); + while (table.firstChild) { + table.removeChild(table.firstChild); + } + for (let [tracker, values] of Object.entries(data)) { + let template = document.querySelector('#tracker_template'); + let node = document.importNode(template.content, true); + node.children[0].children[0].textContent = tracker; + for (let i = 0; i < values.length; i++) { + node.children[0].children[i+1].textContent = values[i]; + } + table.appendChild(node); + } } /* Websocket send */ @@ -75,3 +87,9 @@ function get_active_torrents() { function get_tracker_stats() { socket.send('tracker_stats', {}); } + +/* Helper */ +function update() { + get_active_torrents(); + get_tracker_stats(); +} diff --git a/templates/index.html b/templates/index.html index 2194608..ccae2e0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -75,5 +75,13 @@ {% endfor %} +