#!/usr/bin/env python3 """ A music steaming application. """ import random import asyncpg from fastapi import FastAPI, Request from fastapi.templating import Jinja2Templates from fastapi.staticfiles import StaticFiles from fastapi.responses import HTMLResponse import config #import buckler_fastapi import database as db app = FastAPI() #app.add_middleware(buckler_fastapi.BucklerSessionMiddleware) app.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="templates") @app.get("/", response_class=HTMLResponse) async def index(request: Request): context = {"request": request} return templates.TemplateResponse('index.html', context) @app.get("/rand_track/") async def get_rand_track(request: Request): """Return a random track.""" track = await db.get_random_track(request) return track @app.on_event("startup") async def startup(): app.state.db_pool = await asyncpg.create_pool(**config.db)