Aberrant/aberrant.py
2019-02-18 10:32:19 -05:00

38 lines
941 B
Python

#!/usr/bin/env python3
"""
The primary module for serving the Aberrant application.
"""
import json
import signal
from flask import Flask, render_template, send_from_directory
import rtorrent
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.jinja_env.undefined = "StrictUndefined"
rtorrent.init()
signal.signal(signal.SIGINT, rtorrent.stop_watch)
@app.route("/")
def index():
"""The index page."""
torrents = rtorrent.get_active()
tracker_stats = rtorrent.get_stats()
return render_template("index.html", **locals())
@app.route("/static/<path:path>")
def send_static(path):
"""Sends static files."""
return send_from_directory("static", path)
@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()])
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5250)