示例#1
0
    def test_get_latest_feed(self):
        user1 = backend.add_user('username01','photo_url01','weibo_id01')
        user2 = backend.add_user('username02','photo_url02','weibo_id02')
        user3 = backend.add_user('username03','photo_url03','weibo_id03') 
        user4 = backend.add_user('username04','photo_url04','weibo_id04')

        post1 = backend.add_post('title01',user1['id'],'video_url01',
                    pic_small='pic_small01')
        post2 = backend.add_post('title02',user2['id'],'video_url02',
                    pic_small='pic_small')
        post3 = backend.add_post('title03',user3['id'],'video_url03',
                    pic_small='pic_small03')
        post4 = backend.add_post('title04',user4['id'],'video_url04',
                    pic_small='pic_small04')

        backend.follow_user(user4['id'],user1['id'])
        backend.follow_user(user4['id'],user2['id'])
        

        ret = backend.get_latest_feed(user4['id'],limit=10,offset=0)
        assert len(ret) == 3

        backend.set_post(post3['id'],{'recommended':True})

        ret = backend.get_latest_feed(user4['id'],limit=10,offset=0)
        assert len(ret) == 4
示例#2
0
    def test_get_latest_feed(self):
        user1 = backend.add_user('username01', 'photo_url01', 'weibo_id01')
        user2 = backend.add_user('username02', 'photo_url02', 'weibo_id02')
        user3 = backend.add_user('username03', 'photo_url03', 'weibo_id03')
        user4 = backend.add_user('username04', 'photo_url04', 'weibo_id04')

        post1 = backend.add_post('title01',
                                 user1['id'],
                                 'video_url01',
                                 pic_small='pic_small01')
        post2 = backend.add_post('title02',
                                 user2['id'],
                                 'video_url02',
                                 pic_small='pic_small')
        post3 = backend.add_post('title03',
                                 user3['id'],
                                 'video_url03',
                                 pic_small='pic_small03')
        post4 = backend.add_post('title04',
                                 user4['id'],
                                 'video_url04',
                                 pic_small='pic_small04')

        backend.follow_user(user4['id'], user1['id'])
        backend.follow_user(user4['id'], user2['id'])

        ret = backend.get_latest_feed(user4['id'], limit=10, offset=0)
        assert len(ret) == 3

        backend.set_post(post3['id'], {'recommended': True})

        ret = backend.get_latest_feed(user4['id'], limit=10, offset=0)
        assert len(ret) == 4
示例#3
0
文件: feed.py 项目: Letbeauty/motiky
    def get(self,user_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

        limit = 10
        offset = (page-1) * limit
        
        feeds = backend.get_latest_feed(user_id,limit,offset)

        if len(feeds) > 0:
            feeds = pipe_load(feeds)   
        
        curr_user = backend.get_user_by_uid(g.ukey)
        liked_post_ids = [p['id'] for p in feeds]
        liked_dict = backend.is_like_post(curr_user['id'],liked_post_ids)
        for up in feeds:
            up['is_like'] = liked_dict.get(up['id']) or False

        if page == 1:
            redis.hset(FEED_UPDATE_TIME_KEY % {'user_id':user_id},
                                'last_update_time',int(time.time()))
        return jsonify(results=feeds,page=page)
示例#4
0
    def get(self, user_id):
        try:
            page = int(request.values.get('page'))
        except:
            page = 1

        limit = 10
        offset = (page - 1) * limit

        feeds = backend.get_latest_feed(user_id, limit, offset)

        if len(feeds) > 0:
            feeds = pipe_load(feeds)

        curr_user = backend.get_user_by_uid(g.ukey)
        liked_post_ids = [p['id'] for p in feeds]
        liked_dict = backend.is_like_post(curr_user['id'], liked_post_ids)
        for up in feeds:
            up['is_like'] = liked_dict.get(up['id']) or False

        if page == 1:
            redis.hset(FEED_UPDATE_TIME_KEY % {'user_id': user_id},
                       'last_update_time', int(time.time()))
        return jsonify(results=feeds, page=page)