second commit
This commit is contained in:
parent
b4f8aacc91
commit
680be680e4
|
@ -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.
|
||||
|
|
14
aberrant.py
14
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)
|
||||
|
|
22
rtorrent.py
Normal file
22
rtorrent.py
Normal 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
25
templates/view.html
Normal 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>
|
||||
|
Loading…
Reference in New Issue
Block a user