Example #1
0
async def echo(websocket, path):
    async for message in websocket:
        global db
        db = DB()
        if (message == "recent"):
            await websocket.send(encodeJSONTotal(db.get_all_weekly()))
        elif ("daily" in message):
            await websocket.send(encodeJSON(daily(message[6:])))
        elif ("weekly" in message):
            await websocket.send(encodeJSON(weekly(message[7:])))
        elif ("monthly" in message):
            await websocket.send(encodeJSON(monthly(message[8:])))
        db.close()