示例#1
0
def getExtrasenseAnswer(user=None):
    extrasense = Extrasens()
    count_ext = random.randint(2, 6)  # количество экстрасеносв ответивших
    extData = []
    extID = []
    for i in xrange(count_ext):
        ext_id = extrasense.getRandomExtrasens()
        while (extID.count(ext_id) != 0):
            ext_id = extrasense.getRandomExtrasens()
        extID.append(ext_id)
        ext_id, answer = extrasense.getExtrasenseNumber(ext_id)
        extData.append({
            "name": ext_id.replace("extrasens_", u"Экстрасенс "),
            "id": ext_id,
            "answer": answer
        })

    memcash = MemcachedDB()
    memcash.set("answer_" + user, extData)
    return render_template("extrasense.html", extData=extData)
示例#2
0
def setUserNumber(request, user):
    extrasense = Extrasens()
    memcash = MemcachedDB()
    answer = memcash.get("answer_" + user)
    dt = request.form
    num = int(dt['number'])
    print answer
    print num
    for l in answer:
        if l['answer'] == num:
            extrasense.incCredibility(l['id'])
        else:
            extrasense.decCredibility(l['id'])
    userHis = memcash.get("userHistory_" + user)
    if userHis is None:
        userHis = []

    now = datetime.datetime.now()
    userHis.append({
        "userValue": num,
        "createDate": now.strftime("%d-%m-%Y %H:%M")
    })
    res = memcash.set("userHistory_" + user, userHis)

    [x.pop('name') for x in answer]  # удаляем из ответов лишнее
    extAnser = {}
    extAnser['answer'] = answer
    extAnser['createDate'] = now.strftime("%d-%m-%Y %H:%M")
    res = memcash.get("answerExtrasens_" + user)
    if res == None:
        res = []
    res.append(extAnser)
    memcash.set("answerExtrasens_" + user, res)

    memcash.delete("answer_" + user)
    return render_template("start.html")
示例#3
0
 def incCredibility(self, extrasens):
     memcash = MemcachedDB()
     res = memcash.get('credibility_' + extrasens)
     if res == None:
         res = 1
     else:
         res += 1
     return memcash.set('credibility_' + extrasens, res)
     '''
     while True:
         res,cas = memcash.gets('credibility_'+extrasens)
         print res,cas
         if res in None:
             res = 0
         else :
             res += 1
         if memcash.cas('credibility_'+extrasens,res,cas):
             break
     '''
     pass
示例#4
0
 def setCredibility(self, extrasens, value):
     memcash = MemcachedDB()
     res = memcash.set('credibility_' + extrasens, value)
     return res