From 760760090d99d20c6675ff6fbe9c43a04afc99e1 Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 13 Feb 2019 10:05:11 -0500 Subject: [PATCH] third commit --- aberrant.py | 9 ++------- rtorrent.py | 43 +++++++++++++++++++++++++++++++------------ templates/index.html | 20 ++++++++++++++++++++ templates/view.html | 25 ------------------------- 4 files changed, 53 insertions(+), 44 deletions(-) delete mode 100644 templates/view.html diff --git a/aberrant.py b/aberrant.py index 251066d..34c68fe 100644 --- a/aberrant.py +++ b/aberrant.py @@ -10,18 +10,13 @@ app = Flask(__name__) app.jinja_env.trim_blocks = True app.jinja_env.lstrip_blocks = True app.jinja_env.undefined = "StrictUndefined" +rtorrent.get_all() @app.route("/") def index(): """The index page.""" - return render_template("index.html", **locals()) - -@app.route("/active") -def active(): - """Displays all currently active torrents.""" torrents = rtorrent.get_active() - torrents = [rtorrent.get_info(t) for t in torrents] - return render_template("view.html", **locals()) + return render_template("index.html", **locals()) if __name__ == "__main__": app.run(host='0.0.0.0', port=5250) diff --git a/rtorrent.py b/rtorrent.py index e410ccd..049b44b 100644 --- a/rtorrent.py +++ b/rtorrent.py @@ -4,19 +4,38 @@ This module handles the interface with rTorrent via XMLRPC. """ import xmlrpc.client -_s = xmlrpc.client.ServerProxy("http://localhost:8000/RPC2") +_s = xmlrpc.client.ServerProxy("http://localhost:8000/RPC0") +torrents = [] + +class Torrent: + def __init__(self, raw): + self.hash = raw[0] + self.name = raw[1] + self.active = raw[2] + self.complete = raw[3] + if not self.active: + self.state = "inactive" + elif self.complete: + self.state = "seeding" + else: + self.state = "leeching" + self.downrate = raw[4] + self.uprate = raw[5] def get_all(): - """Returns all torrents in the 'main' view.""" - return _s.download_list("", "main") + """Gets all torrent information and stores it.""" + global torrents + res = _s.d.multicall2('', 'main', + 'd.hash=', + 'd.name=', + 'd.is_active=', + 'd.complete=', + 'd.down.rate=', + 'd.up.rate=', + ) + torrents = [Torrent(raw) for raw in res] def get_active(): - """Returns all torrents in the 'active' view.""" - return _s.download_list("", "active") - -def get_info(torrent): - """Retrieves relevant info about a particular torrent.""" - data = {} - data['name'] = _s.d.name(torrent) - data['complete'] = _s.d.complete(torrent) - return data + """Returns all actively seeding or leeching torrents.""" + active = [t for t in torrents if t.downrate or t.uprate] + return active diff --git a/templates/index.html b/templates/index.html index 9a3ffff..c4a9eae 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,5 +4,25 @@ Aberrant + + + + + + + + + + + {% for torrent in torrents %} + + + + + + + {% endfor %} + +
NameStateDLUL
{{ torrent.name }}{{ torrent.state }}{{ torrent.downrate }}{{ torrent.uprate }}
diff --git a/templates/view.html b/templates/view.html deleted file mode 100644 index f1758ca..0000000 --- a/templates/view.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - Aberrant - - - - - - - - - - - {% for torrent in torrents %} - - - - - {% endfor %} - -
NameComplete
{{ torrent['name'] }}{{ torrent['complete'] }}
- - -