def mark_online(user_ip): config = current_app.config now_time = int(time()) + 28800 expires = config.get('ONLINE_LAST_MINUTES', 5) * 60 online_users = 'online_users:%d' % (now_time // 60) active_users = 'active_users:%s' % user_ip pipe = redis_data.pipeline() if g.user.is_authenticated: online_sign_users = 'online_sign_users:%d' % (now_time // 60) active_sign_users = 'active_sign_users:%s' % user_ip pipe.sadd(online_sign_users, user_ip) pipe.set(active_sign_users, now_time) pipe.expire(online_sign_users, expires) pipe.expire(active_sign_users, expires) pipe.sadd(online_users, user_ip) pipe.set(active_users, now_time) pipe.expire(online_users, expires) pipe.expire(active_users, expires) high = redis_data.hget('online_users', 'high:counts') if not high: pipe.hset('online_users', 'high:counts', 1) high_time = redis_data.hget('online_users', 'high:time') if not high_time: pipe.hset('online_users', 'high:time', now_time) pipe.execute()
def get_read_count(id): read = redis_data.hget('topic:%s' % str(id), 'read') replies = redis_data.hget('topic:%s' % str(id), 'replies') if not read: read = 0 else: read = int(read) if not replies: replies = 0 else: replies = int(replies) return replies, read
def replies_page(topicId): # app = current_app._get_current_object() replies = redis_data.hget('topic:%s' % str(topicId), 'replies') if not replies: replies = 0 else: replies = int(replies) p = current_app.config['PER_PAGE'] if replies % p == 0: q = replies // p else: q = replies // p + 1 return q
def load_online_users(mode): if mode == 1: online_users = load_online_all_users() high_online = redis_data.hget('online_users', 'high:counts') count = len(online_users) if int(high_online) < count: redis_data.hset('online_users', 'high:counts', count) redis_data.hset('online_users', 'high:time', int(time()) + 28800) return count if mode == 2: # 'online sign users' online_users = load_online_sign_users() return len(online_users) if mode == 3: # 'guest users' online_users = load_online_all_users() online_sign_users = load_online_sign_users() return len(online_users) - len(online_sign_users) if mode == 4: counts = redis_data.hget('online_users', 'high:counts') return counts if mode == 5: high_time = redis_data.hget('online_users', 'high:time') return datetime.utcfromtimestamp(int(high_time))
def wrapper(*args, **kw): time = redis_data.hget('user:%s' % str(current_user.id), 'send_email_time') if time: try: time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S') if datetime.utcnow() < time + timedelta(seconds=360): return HTTPResponse( HTTPResponse.USER_EMAIL_WAIT).to_response() except TypeError: set_email_send(current_user.id) except ValueError: set_email_send(current_user.id) else: set_email_send(current_user.id) return func(*args, **kw)
def get_repies_count(qid): pages = redis_data.hget('topic:%s' % str(qid), 'replies') return pages