Beispiel #1
0
def mark_online(user_ip):
    '''记录在线用户'''
    pipe = redis_data.pipeline()
    config = current_app.config
    now_time = int(time()) + 28800
    expires = config['ONLINE_LAST_MINUTES'] * 60
    '''分钟'''
    online_users = 'online_users:%d' % (now_time // 60)
    active_users = 'active_users:%s' % user_ip
    '''注册用户'''
    if g.user is not None and 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()
Beispiel #2
0
def mark_online(user_ip):
    '''记录在线用户'''
    pipe = redis_data.pipeline()
    config = current_app.config
    now_time = int(time()) + 28800
    expires = config['ONLINE_LAST_MINUTES'] * 60
    '''分钟'''
    online_users = 'online_users:%d' % (now_time // 60)
    active_users = 'active_users:%s' % user_ip
    '''注册用户'''
    if g.user is not None and 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()
Beispiel #3
0
def load_read_count(id):
    read = redis_data.hget('question:%s' % str(id), 'read')
    replies = redis_data.hget('question:%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
Beispiel #4
0
def load_read_count(id):
    read = redis_data.hget('question:%s'%str(id),'read')
    replies = redis_data.hget('question:%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
Beispiel #5
0
 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
Beispiel #6
0
def judge(id,mode):
    if mode == 'collect':
        from maple.question.models import Collector
        collect = Collector.load_by_id(id,current_user.id)
        if collect:
            return True
        else:
            return False
    if mode == 'love':
        from maple.question.models import Lover
        lover = Lover.load_by_id(id,current_user.id)
        if lover:
            return True
        else:
            return False
    if mode == 'daily':
        user = '******' + ':' +  'daily' + ':' + str(id)
        if redis_data.exists(user):
            return True
        else:
            return False
    if mode == 'notice':
        user = '******' + ':' + str(id)
        notice = redis_data.hget(user,'notice')
        if not notice:
            notice = 0
        else:
            notice = int(notice)
        return notice
Beispiel #7
0
def judge(id, mode):
    if mode == 'collect':
        from maple.question.models import Collector
        collect = Collector.load_by_id(id, current_user.id)
        if collect:
            return True
        else:
            return False
    if mode == 'love':
        from maple.question.models import Lover
        lover = Lover.load_by_id(id, current_user.id)
        if lover:
            return True
        else:
            return False
    if mode == 'daily':
        user = '******' + ':' + 'daily' + ':' + str(id)
        if redis_data.exists(user):
            return True
        else:
            return False
    if mode == 'notice':
        user = '******' + ':' + str(id)
        notice = redis_data.hget(user, 'notice')
        if not notice:
            notice = 0
        else:
            notice = int(notice)
        return notice
Beispiel #8
0
def load_user_count(id):
    topic = redis_data.hget('user:%s'%str(current_user.id),'topic')
    all_topic = redis_data.hget('user:%s'%str(current_user.id),'all_topic')
    collect = redis_data.hget('user:%s'%str(current_user.id),'collect')
    if not topic:
        topic = 0
    else:
        topic = int(topic)
    if not all_topic:
        all_topic = 0
    else:
        all_topic = int(all_topic)
    if not collect:
        collect = 0
    else:
        collect = int(collect)
    return topic,all_topic,collect
Beispiel #9
0
def load_forums_count(id):
    topic = redis_data.hget('forums:count','topic')
    group = redis_data.hget('forums:count','group')
    user = redis_data.hget('forums:count','user')
    if not topic:
        topic = 0
    else:
        topic = int(topic)
    if not group:
        group = 0
    else:
        group = int(group)
    if not user:
        user = 0
    else:
        user = int(user)
    return topic,group,user
Beispiel #10
0
def load_user_count(id):
    topic = redis_data.hget('user:%s' % str(current_user.id), 'topic')
    all_topic = redis_data.hget('user:%s' % str(current_user.id), 'all_topic')
    collect = redis_data.hget('user:%s' % str(current_user.id), 'collect')
    if not topic:
        topic = 0
    else:
        topic = int(topic)
    if not all_topic:
        all_topic = 0
    else:
        all_topic = int(all_topic)
    if not collect:
        collect = 0
    else:
        collect = int(collect)
    return topic, all_topic, collect
Beispiel #11
0
def load_forums_count(id):
    topic = redis_data.hget('forums:count', 'topic')
    group = redis_data.hget('forums:count', 'group')
    user = redis_data.hget('forums:count', 'user')
    if not topic:
        topic = 0
    else:
        topic = int(topic)
    if not group:
        group = 0
    else:
        group = int(group)
    if not user:
        user = 0
    else:
        user = int(user)
    return topic, group, user
Beispiel #12
0
def load_online_users(mode):
    if mode == 'counts':
        counts = len(load_online_all_users()) - len(load_online_sign_users())
        return counts
    if mode == 'all_counts':
        counts = len(load_online_all_users())
        high = redis_data.hget('online_users', 'high:counts')
        if counts > int(high):
            redis_data.hset('online_users', 'high:counts', counts)
            redis_data.hset('online_users', 'high:time', int(time()) + 28800)
        return counts
    if mode == 'sign_counts':
        return len(load_online_sign_users())
    if mode == 'high':
        counts = redis_data.hget('online_users', 'high:counts')
        return int(counts)
    if mode == 'high_time':
        high_time = redis_data.hget('online_users', 'high:time')
        return datetime.utcfromtimestamp(int(high_time))
Beispiel #13
0
def load_online_users(mode):
    if mode == 'counts':
        counts = len(load_online_all_users()) - len(load_online_sign_users())
        return counts
    if mode == 'all_counts':
        counts = len(load_online_all_users())
        high = redis_data.hget('online_users', 'high:counts')
        if counts > int(high):
            redis_data.hset('online_users', 'high:counts', counts)
            redis_data.hset('online_users', 'high:time', int(time()) + 28800)
        return counts
    if mode == 'sign_counts':
        return len(load_online_sign_users())
    if mode == 'high':
        counts = redis_data.hget('online_users', 'high:counts')
        return int(counts)
    if mode == 'high_time':
        high_time = redis_data.hget('online_users', 'high:time')
        return datetime.utcfromtimestamp(int(high_time))
Beispiel #14
0
def category(category, number):
    user = User.query.filter_by(name=g.user_url).first_or_404()
    user_count = redis_data.hget('user:%s' % str(user.id), 'topic')
    if not user_count:
        user_count = 0
    else:
        user_count = int(user_count)
    return render_template('user/user.html',
                           user=user,
                           category=category,
                           user_count=user_count)
Beispiel #15
0
def category(category, number):
    user = User.query.filter_by(name=g.user_url).first_or_404()
    user_count = redis_data.hget('user:%s' % str(user.id), 'topic')
    if not user_count:
        user_count = 0
    else:
        user_count = int(user_count)
    return render_template('user/user.html',
                           user=user,
                           category=category,
                           user_count=user_count)
Beispiel #16
0
 def allow(self):
     user = '******' % str(current_user.id)
     last_time = redis_data.hget(user, 'send_email_time')
     now_time = int(time()) + 28800
     if last_time is None:
         last_time = now_time
         return True
     else:
         last_time = int(last_time)
     if last_time < now_time - 3600:
         return True
     else:
         return False
Beispiel #17
0
 def allow(self):
     user = '******' % str(current_user.id)
     last_time = redis_data.hget(user, 'send_email_time')
     now_time = int(time()) + 28800
     if last_time is None:
         last_time = now_time
         return True
     else:
         last_time = int(last_time)
     if last_time < now_time - 3600:
         return True
     else:
         return False
Beispiel #18
0
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
Beispiel #19
0
def index():
    user = User.query.filter_by(name=g.user_url).first_or_404()
    if g.user is not None and g.user.is_authenticated:
        user_count = redis_data.hget('user:%s' % str(current_user.id), 'topic')
        if not user_count:
            user_count = 0
        else:
            user_count = int(user_count)
        return render_template('user/user.html',
                               user_count=user_count,
                               category='',
                               user=user)
    else:
        return render_template('user/user.html', user=user, category='')
Beispiel #20
0
def index():
    user = User.query.filter_by(name=g.user_url).first_or_404()
    if g.user is not None and g.user.is_authenticated:
        user_count = redis_data.hget('user:%s' % str(current_user.id), 'topic')
        if not user_count:
            user_count = 0
        else:
            user_count = int(user_count)
        return render_template('user/user.html',
                               user_count=user_count,
                               category='',
                               user=user)
    else:
        return render_template('user/user.html', user=user, category='')
Beispiel #21
0
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))
Beispiel #22
0
 def wrapper(*args, **kw):
     time = redis_data.hget('user:%s' % str(current_user.id),
                            'send_email_time')
     print(time)
     try:
         time = time.split('.')[0]
         time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
         print(time)
         if datetime.now() < time + timedelta(seconds=360):
             return jsonify(judge=False, error="你获取的验证链接还未过期,请尽快验证")
     except TypeError:
         set_email_send(current_user.id)
     except ValueError:
         set_email_send(current_user.id)
     return func(*args, **kw)
Beispiel #23
0
 def time_permission(self):
     if request.method == "POST":
         user = '******' % str(current_user.id)
         last_time = redis_data.hget(user, 'send_email_time')
         now_time = int(time()) + 28800
         if not last_time:
             last_time = now_time
         else:
             last_time = int(last_time)
         if last_time > now_time - 3600:
             error = u'你的验证链接还未过期,请尽快验证'
             return error
         else:
             pass
     else:
         abort(404)
Beispiel #24
0
 def time_permission(self):
     if request.method == "POST":
         user = '******' % str(current_user.id)
         last_time = redis_data.hget(user, 'send_email_time')
         now_time = int(time()) + 28800
         if not last_time:
             last_time = now_time
         else:
             last_time = int(last_time)
         if last_time > now_time - 3600:
             error = u'你的验证链接还未过期,请尽快验证'
             return error
         else:
             pass
     else:
         abort(404)
Beispiel #25
0
 def get_all_topics(self):
     topics_num = redis_data.hget('users', 'topics')
     return topics_num
Beispiel #26
0
 def get_all_users(self):
     users_num = redis_data.hget('users', 'numbers')
     return users_num
Beispiel #27
0
 def get_all_replies(self):
     replies_count_num = redis_data.hget('topics', 'replies')
     return replies_count_num
Beispiel #28
0
 def get_repies_count(qid):
     pages = redis_data.hget('topic:%s' % str(qid), 'replies')
     return pages
Beispiel #29
0
 def get_repies_count(qid):
     pages = redis_data.hget('question:%s' % str(qid), 'replies')
     return pages