second commit

This commit is contained in:
iou1name 2019-01-16 12:49:42 -05:00
parent b4f8aacc91
commit 680be680e4
4 changed files with 61 additions and 2 deletions

View File

@ -10,7 +10,7 @@ Python packages: `flask gunicorn`
2. Walk the dinosaur 2. Walk the dinosaur
## Usage ## 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? ## What's with the name?
Picked a random word from the dictionary desu. Picked a random word from the dictionary desu.

View File

@ -4,12 +4,24 @@ The primary module for serving the Aberrant application.
""" """
from flask import Flask, render_template from flask import Flask, render_template
import rtorrent
app = Flask(__name__) app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.jinja_env.undefined = "StrictUndefined"
@app.route("/") @app.route("/")
def index(): def index():
"""The index page.""" """The index page."""
return render_template("index.html", **locals()) 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__": if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000) app.run(host='0.0.0.0', port=5250)

22
rtorrent.py Normal file
View File

@ -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

25
templates/view.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Aberrant</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Complete</th>
</tr>
</thead>
<tbody>
{% for torrent in torrents %}
<tr>
<td>{{ torrent['name'] }}</td>
<td>{{ torrent['complete'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>