Beispiel #1
0
async def save(client, dbFileName, message):
    accounts = utilities.unpackAccounts(message["accounts"])
    packages = utilities.unpackPackages(message["packages"])

    database.save(dbFileName, accounts, packages)

    successful = [
        entity["entity"] for entity in packages
        if entity["status"] == "success"
    ]
    print("successful               ", successful)

    await messages.respond(
        client, message, {
            "packages": [{
                "entity":
                utilities.packPackages([entity["entity"]])[0],
                **(utilities.packEntities([entity])[0])
            } for entity in packages]
        })

    changedUsernames = set([package["username"] for package in successful])
    clients2usernames = connections.getClients(changedUsernames)
    for otherClient, usernames in clients2usernames.items():
        usernames = list(usernames)
        await messages.send(otherClient, 'packages changed',
                            {'usernames': usernames})
Beispiel #2
0
async def createAccounts(client, dbFileName, message):
    entities = database.createAccounts(
        dbFileName, utilities.unpackAccounts(message["accounts"]))

    await messages.respond(
        client, message, {
            "accounts": [{
                "entity":
                utilities.packAccounts([entity["entity"]])[0],
                **(utilities.packEntities([entity])[0])
            } for entity in entities]
        })