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)
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']
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
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
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 = []
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
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))
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
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('<', '<').replace('>', '>') 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
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 = []
def __init__(self): self.es = Elasticsearch() self.db = redis.db('log') self.actions = []