From 680be680e47e1a7a56a8a108bc720369ba23722f Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 16 Jan 2019 12:49:42 -0500 Subject: [PATCH] second commit --- README.md | 2 +- aberrant.py | 14 +++++++++++++- rtorrent.py | 22 ++++++++++++++++++++++ templates/view.html | 25 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 rtorrent.py create mode 100644 templates/view.html 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 @@ + + + + Aberrant + + + + + + + + + + + {% for torrent in torrents %} + + + + + {% endfor %} + +
NameComplete
{{ torrent['name'] }}{{ torrent['complete'] }}
+ + +