Aberrant/aberrant.py

38 lines
941 B
Python
Raw Normal View History

2019-01-16 09:33:36 -05:00
#!/usr/bin/env python3
"""
The primary module for serving the Aberrant application.
"""
2019-02-15 10:01:33 -05:00
import json
2019-02-14 15:00:21 -05:00
import signal
from flask import Flask, render_template, send_from_directory
2019-01-16 09:33:36 -05:00
2019-01-16 12:49:42 -05:00
import rtorrent
2019-01-16 09:33:36 -05:00
app = Flask(__name__)
2019-01-16 12:49:42 -05:00
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.jinja_env.undefined = "StrictUndefined"
2019-02-14 15:00:21 -05:00
rtorrent.init()
signal.signal(signal.SIGINT, rtorrent.stop_watch)
2019-01-16 09:33:36 -05:00
@app.route("/")
def index():
"""The index page."""
2019-01-16 12:49:42 -05:00
torrents = rtorrent.get_active()
2019-02-18 10:32:19 -05:00
tracker_stats = rtorrent.get_stats()
2019-02-13 10:20:55 -05:00
return render_template("index.html", **locals())
2019-01-16 12:49:42 -05:00
2019-02-14 15:00:21 -05:00
@app.route("/static/<path:path>")
def send_static(path):
"""Sends static files."""
return send_from_directory("static", path)
2019-02-15 10:01:33 -05:00
@app.route("/get_active_torrents")
def get_active_torrents():
"""Returns all active torrents formatted as JSON."""
return json.dumps([vars(t) for t in rtorrent.get_active()])
2019-01-16 09:33:36 -05:00
if __name__ == "__main__":
2019-01-16 12:49:42 -05:00
app.run(host='0.0.0.0', port=5250)