#!/usr/bin/env python3 """ WebSocket events. """ import types async def select(request, ws, data): """Retrieve information about an artist, album or track.""" if data.get('type') == 'artist': async with request.app['pool'].acquire() as conn: albums = await conn.fetch( "SELECT DISTINCT album, date FROM track " "WHERE albumartist = $1 ORDER BY date ASC", data.get('artist', '')) albums = [record['album'] for record in albums] ret = {'event': 'albums', 'ok': True, 'data': albums} await ws.send_json(ret) events = {} for obj in dir(): if type(locals()[obj]) == types.FunctionType: events[locals()[obj].__name__] = locals()[obj]