예제 #1
0
파일: dbfunc.py 프로젝트: Mb01/playground
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
예제 #2
0
파일: dbfunc.py 프로젝트: 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
예제 #3
0
파일: dbfunc.py 프로젝트: 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
예제 #4
0
파일: dbfunc.py 프로젝트: Mb01/playground
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