third commit

This commit is contained in:
iou1name 2019-02-13 10:20:55 -05:00
parent 680be680e4
commit 70c95d28af
4 changed files with 53 additions and 44 deletions

View File

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

View File

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

View File

@ -4,5 +4,25 @@
<title>Aberrant</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>State</th>
<th>DL</th>
<th>UL</th>
</tr>
</thead>
<tbody>
{% for torrent in torrents %}
<tr>
<td>{{ torrent.name }}</td>
<td>{{ torrent.state }}</td>
<td>{{ torrent.downrate }}</td>
<td>{{ torrent.uprate }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

View File

@ -1,25 +0,0 @@
<!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>