import json

openGuild = open("./userinfo/guildinfo.json", "r")
parsedGuild = json.loads(openGuild.read())

openUser = open("./userinfo/userinfo.json", "r")
parsedUser = json.loads(openUser.read())

parsed = {
    "guild": parsedGuild,
    "user": parsedUser
}

async def flush():
    writeUser = open("./userinfo/userinfo.json", "w")
    writeUser.write(json.dumps(parsed["user"]))
    writeUser.close()

    writeGuild = open("./userinfo/guildinfo.json", "w")
    writeGuild.write(json.dumps(parsed["guild"]))
    writeGuild.close()

async def get(file):
    return parsed[file]

async def find(file, index, value):
    for Info in parsed[file]:
        if Info[index] == value:
            return Info
    return None