Beispiel #1
0
 def check_answer(identifier, form, ua):
     highscore = False
     _id = int(form['_id']) ^ identifier
     (post_dt, post) = get_log_by_id(_id)
     t_delta = datetime.now() - post_dt
     db = redis.db('now_or_past')
     if is_correct(t_delta, form['res']):
         prev = db.get('prev:%s' % identifier) or 0
         if _id != int(prev):
             score = db.incr('win:%s' % identifier)
             answer = '[%d おまんこ] ' % score + random.choice(CORRECT_MSGS)
             sound = 'right'
             db.expire('win:%s' % identifier, 300)
             db.setex('prev:%s' % identifier, _id, 300)
         else:
             answer = 'リロードしたので正解数をリセットします(゚Д`)'
             sound = 'wrong'
             db.setex('win:%s' % identifier, 0, 300)
     else:
         answer = '[おちんぽ] ' + random.choice(INCORRECT_MSGS)
         sound = 'wrong'
         score = db.get('win:%s' % identifier) or 0
         score = int(score)
         if score and is_highscore(score):
             db.setex('highscore:%s' % identifier, score, 3000)
             highscore = score
         db.setex('win:%s' % identifier, 0, 300)
     post_dt = Markup(parse_dt(post_dt) + gen_usamin_link(_id))
     return render_template('now_or_past.html', post_dt=post_dt, css=determine_css(ua),
                            highscore=highscore, post=Markup(post), answer=Markup(answer),
                            sound=sound)
Beispiel #2
0
def dialogue():
    def explicit_fword(text):
        for (implicit, explicit) in fwords.items():
            text = text.replace(implicit, explicit)
        return text

    _input = request.args.get('text')
    _input = explicit_fword(_input)

    uid = compute_id(request)
    db = redis.db('twitter')
    user_info = db.get('user:%s' % uid)
    if user_info:
        user_info = json.loads(user_info.decode('utf8'))
        user_info['tweets'].append(_input)
    else:
        user_info = {'replies': [], 'tweets': [_input]}
    user_info.update({'screen_name': '貴殿', 'name': '貴殿'})

    rep = Reply()
    response = rep.make_response(_input, user_info)
    if len(user_info['replies']) >= 20:
        user_info['replies'].pop(0)
    if len(user_info['tweets']) >= 20:
        user_info['tweets'].pop(0)
    user_info['replies'].append(response['text'])
    db.setex('user:%s' % uid, json.dumps(user_info), TWO_WEEK)
    response['text'] = normalize.remove_emoticon(response['text'])
    response['text'] = response['text'].strip()
    return response['text']
Beispiel #3
0
def dialogue():
    def explicit_fword(text):
        for (implicit, explicit) in fwords.items():
            text = text.replace(implicit, explicit)
        return text

    _input = request.args.get('text')
    _input = explicit_fword(_input)

    uid = compute_id(request)
    db = redis.db('twitter')
    user_info = db.get('user:%s' % uid)
    if user_info:
        user_info = json.loads(user_info.decode('utf8'))
        user_info['tweets'].append(_input)
    else:
        user_info = {'replies': [], 'tweets': [_input]}
    user_info.update({'screen_name': '貴殿', 'name': '貴殿'})

    rep = Reply()
    response = rep.make_response(_input, user_info)
    if len(user_info['replies']) >= 20:
        user_info['replies'].pop(0)
    if len(user_info['tweets']) >= 20:
        user_info['tweets'].pop(0)
    user_info['replies'].append(response['text'])
    db.setex('user:%s' % uid, json.dumps(user_info), TWO_WEEK)
    response['text'] = normalize.remove_emoticon(response['text'])
    response['text'] = response['text'].strip()
    return response['text']
Beispiel #4
0
 def __init__(self, debug=False):
     self.tl_responder = TimeLineReply()
     self.reply_responder = Reply()
     self.twitter = Twitter()
     self.db = redis.db('twitter')
     if not self.db.exists('latest_tl_replied'):
         self.db.set('latest_tl_replied', '(;´Д`)')
     self.debug = debug
Beispiel #5
0
 def __init__(self, debug=False):
     self.tl_responder = TimeLineReply()
     self.reply_responder = Reply()
     self.twitter = Twitter()
     self.db = redis.db("twitter")
     if not self.db.exists("latest_tl_replied"):
         self.db.set("latest_tl_replied", "(;´Д`)")
     self.debug = debug
Beispiel #6
0
 def __init__(self):
     self.cfg = file_io.read('atango.json')['Reply']
     self.twitter = api.Twitter()
     self.db = redis.db('twitter')
     global_context = self.db.get('global_context')
     if global_context:
         self.global_context = json.loads(global_context.decode('utf8'))
     else:
         self.global_context = []
Beispiel #7
0
 def __init__(self):
     self.cfg = file_io.read('atango.json')['Reply']
     self.twitter = api.Twitter()
     self.db = redis.db('twitter')
     global_context = self.db.get('global_context')
     if global_context:
         self.global_context = json.loads(global_context.decode('utf8'))
     else:
         self.global_context = []
Beispiel #8
0
 def is_highscore(score):
     db = redis.db('now_or_past')
     highscores = db.zrangebyscore('score', 0, 0x01 << 64, withscores=True, score_cast_func=int)
     if len(highscores) < NUM_RANKING:
         return True
     unique_scores = set()
     for (name, highscore) in highscores:
         if score > int(highscore):
             return True
         unique_scores.add(highscore)
     return len(unique_scores) < NUM_RANKING
Beispiel #9
0
def ranking():
    ua = request.headers.get('User-Agent')
    db = redis.db('now_or_past')
    highscores = ''
    unique_scores = set()
    for (name, score) in db.zrevrangebyscore('score', 0x01 << 64, 0, withscores=True,
                                             score_cast_func=int):
        unique_scores.add(score)
        rank = len(unique_scores)
        name = name.decode('utf8').replace('___', ' ')
        highscores += HIGHSCORE_FORMAT % (rank, name, score)
    return render_template('ranking.html', highscores=Markup(highscores), css=determine_css(ua))
Beispiel #10
0
    def test_get_userinfo(self):
        db = redis.db('twitter')
        db.delete('user:0')

        tweet = {'id': 0, 'user': {'id': 0, 'name': 'まんこ', 'screen_name': 'manko'},
                 'text': 'おまんこ', 'created_at': '2015-03-09', 'source': 'm'}
        actual = self.rep.get_userinfo(tweet)
        desired = {'name': 'まんこ', 'screen_name': 'manko', 'tweets': ['おまんこ'], 'replies': []}
        assert actual == desired

        userinfo = {'name': 'まんこ', 'screen_name': 'manko',
                    'tweets': ['おまんこ', 'まんこ'], 'replies': ['manko', 'omanko']}
        db.set('user:0', json.dumps(userinfo))
        actual = self.rep.get_userinfo(tweet)
        userinfo['tweets'] = ['おまんこ', 'まんこ', 'おまんこ']
        assert actual == userinfo
Beispiel #11
0
 def entry_highscore(identifier, user_name):
     db = redis.db('now_or_past')
     score = db.get('highscore:%s' % identifier) or 0
     score = int(score)
     if not score:
         return False
     user_name = user_name.replace('<', '&lt;').replace('>', '&gt;')
     user_name += datetime.now().strftime('___(%Y/%m/%d___%H:%M:%S)')
     db.zadd('score', user_name, score)
     highscores = db.zrevrangebyscore('score', 0x01 << 64, 0, withscores=True,
                                      score_cast_func=int)
     unique_scores = set()
     for (name, highscore) in highscores:
         if (score > highscore and highscore not in unique_scores and
                 len(unique_scores) > NUM_RANKING - 1):
             db.zrem('score', name)
         else:
             unique_scores.add(highscore)
     db.bgsave()
     return True
Beispiel #12
0
 def __init__(self, es_setting=None):
     self.es = Elasticsearch(es_setting)
     self.db = redis.db('log')
     self.actions = []
 def __init__(self):
     self.es = Elasticsearch([elasticsearch_setting])
     self.db = redis.db('log')
     self.actions = []
Beispiel #14
0
 def __init__(self):
     self.es = Elasticsearch()
     self.db = redis.db('log')
     self.actions = []