Exemplo n.º 1
0
 def decCredibility(self, extrasens):
     memcash = MemcachedDB()
     res = memcash.get('credibility_' + extrasens)
     if res == None:
         res = 0
     else:
         memcash.decr('credibility_' + extrasens)
     pass
Exemplo n.º 2
0
def getUserHistory(user):
    memcash = MemcachedDB()
    res = memcash.get("userHistory_" + user)
    if res != None:
        res.reverse()
    else:
        res = []
    return res
Exemplo n.º 3
0
 def getCredibilityAll(self):
     memcash = MemcachedDB()
     res = []
     for ext in self.extrasens:
         val = memcash.get('credibility_' + ext)
         if val == None:
             val = 0
         res.append({"name": ext, "val": val})
         pass
     return res
Exemplo n.º 4
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")
Exemplo n.º 5
0
def getExtrasenseHistory(user):
    memcash = MemcachedDB()
    res = memcash.get("answerExtrasens_" + user)
    print res
    if res == None:
        res = []
    res.reverse()
    out = []
    for l in res:
        dt = l['createDate']
        ans = [
            x['id'].replace('extrasens_', u'Экстрасенс ') + ' : ' +
            str(x['answer']) for x in l['answer']
        ]
        ans = ' / '.join(ans)
        out.append({'createDate': dt, 'answer': ans})
    return out
Exemplo n.º 6
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
Exemplo n.º 7
0
 def getCredibility(self, extrasens):
     memcash = MemcachedDB()
     val = memcash.get('credibility_' + extrasens)
     if val == None:
         return 0
     return val