diff --git a/README.md b/README.md index e4886a4..a4a1f71 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Python packages: `flask gunicorn` 2. Walk the dinosaur ## Usage -`gunicorn -b localhost:5000 -e SCRIPT_NAME=/aberrant aberrant:app` +`gunicorn -b localhost:5250 -e SCRIPT_NAME=/aberrant aberrant:app` ## What's with the name? Picked a random word from the dictionary desu. diff --git a/aberrant.py b/aberrant.py index a10c728..251066d 100644 --- a/aberrant.py +++ b/aberrant.py @@ -4,12 +4,24 @@ The primary module for serving the Aberrant application. """ from flask import Flask, render_template +import rtorrent + app = Flask(__name__) +app.jinja_env.trim_blocks = True +app.jinja_env.lstrip_blocks = True +app.jinja_env.undefined = "StrictUndefined" @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()) + if __name__ == "__main__": - app.run(host='0.0.0.0', port=5000) + app.run(host='0.0.0.0', port=5250) diff --git a/rtorrent.py b/rtorrent.py new file mode 100644 index 0000000..e410ccd --- /dev/null +++ b/rtorrent.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +""" +This module handles the interface with rTorrent via XMLRPC. +""" +import xmlrpc.client + +_s = xmlrpc.client.ServerProxy("http://localhost:8000/RPC2") + +def get_all(): + """Returns all torrents in the 'main' view.""" + return _s.download_list("", "main") + +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 diff --git a/templates/view.html b/templates/view.html new file mode 100644 index 0000000..f1758ca --- /dev/null +++ b/templates/view.html @@ -0,0 +1,25 @@ + + +
+Name | +Complete | +
---|---|
{{ torrent['name'] }} | +{{ torrent['complete'] }} | +