Exemplo n.º 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()
Exemplo n.º 2
0
import asyncio
import websockets
from MySQL import DB
import json
import datetime

db = DB()
#this is all terrible old code and needs to be severly rewritten for a larger scale project :/


def encodeJSONTotal(data):
    JSONData = {}
    for i in range(len(data)):
        if JSONData.get(data[i][0]) != None:
            JSONData[data[i][0]]['minutes'] += 1
        else:
            JSONData[data[i][0]] = {'minutes': 1}
    return json.dumps(JSONData)


def encodeJSON(data):
    return json.dumps(data)


def daily(name):
    info = db.get_user_daily(name)
    day = {}
    for k in info:
        if day.get(k[1].hour):
            day[k[1].hour] += 1
        else:
Exemplo n.º 3
0
def main():
    database = DB()
    repository = Repository(database)
    controller = Controller(repository)
    view = View(controller)
    view.mainMenu()