47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
|
#!/usr/bin/env python3
|
||
|
"""
|
||
|
A display interface for archived 4chan quest threads.
|
||
|
"""
|
||
|
from aiohttp import web
|
||
|
import jinja2
|
||
|
import aiohttp_jinja2
|
||
|
from aiohttp_jinja2 import render_template
|
||
|
import asyncpg
|
||
|
import uvloop
|
||
|
|
||
|
import config
|
||
|
|
||
|
uvloop.install()
|
||
|
routes = web.RouteTableDef()
|
||
|
|
||
|
@routes.get('/', name='index')
|
||
|
async def index(request):
|
||
|
"""The index page."""
|
||
|
async with request.app['pool'].acquire() as conn:
|
||
|
threads = await conn.fetch("SELECT * FROM thread ORDER BY time ASC")
|
||
|
return render_template("index.html", request, locals())
|
||
|
|
||
|
|
||
|
async def init_app():
|
||
|
"""Initializes the application."""
|
||
|
app = web.Application()
|
||
|
aiohttp_jinja2.setup(
|
||
|
app,
|
||
|
trim_blocks=True,
|
||
|
lstrip_blocks=True,
|
||
|
undefined=jinja2.StrictUndefined,
|
||
|
loader=jinja2.FileSystemLoader('templates'),
|
||
|
)
|
||
|
app['pool'] = await asyncpg.create_pool(**config.db)
|
||
|
|
||
|
app.router.add_routes(routes)
|
||
|
|
||
|
app_wrap = web.Application()
|
||
|
app_wrap.add_subapp(config.url_prefix, app)
|
||
|
return app_wrap
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
app = init_app()
|
||
|
web.run_app(app, host='0.0.0.0', port=5450)
|