#!/usr/bin/env python3 """ The primary module for serving the Aberrant application. """ import jinja2 import aiohttp_jinja2 from aiohttp import web, WSMsgType from aiohttp_jinja2 import render_template import config import rtorrent app = web.Application() app.on_shutdown.append(rtorrent.stop_watch) aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates')) rtorrent.init() routes = web.RouteTableDef() @routes.get(config.prefix + "/", name='index') def index(request): """The index page.""" torrents = rtorrent.get_active() tracker_stats = rtorrent.get_stats() return render_template("index.html", request, locals()) @routes.get(config.prefix + "/get_active_torrents", name='active-torrents') def get_active_torrents(request): """Returns all active torrents formatted as JSON.""" data = [vars(t) for t in rtorrent.get_active()] return web.json_response(data) app.router.add_routes(routes) if __name__ == "__main__": aiohttp.web.run_app(app, host='0.0.0.0', port=5250)