Example #1
0
def getQuestionKeys(genre, update=False):
    """memset all the KEYS under the GENRE return the keys"""
    questions = memg(genre)
    if (not questions) or update:
        questions = Question.all(keys_only=True).filter("genre =", genre)
        questions = [x for x in questions]
        mems(genre, questions)
    return questions
Example #2
0
File: dbfunc.py Project: Mb01/yasai
def getInventory(update=False):
    inventory = memg("_inventory123")
    if (not inventory) or update:
        if update:
            logging.info("update: inventory hits db")
        else:
            logging.info("inventory hit db")
        inventory = {}
        stores = Store.all()
        for store in stores:
            inventory[store.name] = {}
            items = Item.all().ancestor(store.key())
            for item in items:
                item = item.asDict()
                inventory[store.name][item["name"]] = item
        mems("_inventory123", inventory)
    else:
        logging.info("inventory hits cache")
    return inventory
Example #3
0
File: dbfunc.py Project: Mb01/yasai
def getInventory(update=False):
    inventory = memg("_inventory123")
    if (not inventory) or update:
        if update:
            logging.info("update: inventory hits db")
        else:
            logging.info("inventory hit db")
        inventory = {}
        stores = Store.all()
        for store in stores:
            inventory[store.name] = {}
            items = Item.all().ancestor(store.key())
            for item in items:
                item = item.asDict()
                inventory[store.name][item["name"]] = item
        mems("_inventory123", inventory)
    else:
        logging.info("inventory hits cache")
    return inventory
Example #4
0
def getQuestion(genre):
    """to get a question by genre"""
    if not genre:
        genre = "general"
    questions = getQuestionKeys(genre)
    if not questions:
        logging.error("dbfunc.py line 39: couldn't return a question for: " + genre)
        questions = getQuestionKeys("general")
    ranChoice = random.choice(questions)
    # not in cache get from db set cache
    q = memg(str(ranChoice))
    if not q:
        q = db.get(ranChoice)
        mems(str(ranChoice), q)
    q = q.asDict()
    options = [q["answer"], q["choice1"], q["choice2"], q["choice3"]]
    random.shuffle(options)
    q["options"] = options
    q["hashed"] = makeCookieHash(q["answer"])
    return q