Exemple #1
0
def get_hot_post():
    """
    获取最火的3个帖子
    """
    hots = []
    res = mdb.baidu.post.find(
        {
            'is_open': settings.get('post_flag'),
            'post_cover_img': {
                '$exists': True
            }
        },
        sort=[('last_click_time', -1)],
        limit=6,
        fields={
            '_id': False,
            'url': True,
            'post_cover_img': True,
            'title': True
        })
    for p in res:
        p['post_cover_img'] = tools.imgurl(p['post_cover_img'],
                                           pformat='-cover300')
        hots.append(p)
    return hots
Exemple #2
0
    def get(self):
        """
        """
        page = int(self.get_argument('page', 1))
        album_list = mdb.baidu.post.find(
            {
                'is_open': settings.get('post_flag'),
                'reply_img_count': {
                    '$gt': 2
                }
            },
            fields={
                'reply_img_list': True,
                'title': True,
                '_id': False
            },
            sort=[('find_time', -1)],
            skip=20 * (page - 1),
            limit=20)
        album_list = list(album_list)
        for idx, album in enumerate(album_list):
            pics = []
            for pic in album['reply_img_list']:
                pic = tools.imgurl(pic, pformat='-cover300')
                #pic = tools.imgurl(pic)
                pics.append(pic)
            album_list[idx]['pic_list'] = pics
            album_list[idx].pop('reply_img_list')

        self.finish(json.dumps({'fuli_list': album_list}))
Exemple #3
0
 def get(self):
     page = int(self.get_argument('page', 1))
     count = 30
     post_list = []
     res = mdb.baidu.post.find(
         {
             'is_open': 0,
             'post_cover_img': {
                 '$exists': True
             }
         },
         sort=[('find_time', -1)],
         skip=(page - 1) * count,
         limit=count,
         fields={
             'title': True,
             'post_cover_img': True
         })
     for p in res:
         #p['abstract'] = get_post_abstract(p)
         if p.get('post_cover_img'):
             p['post_cover_img'] = tools.imgurl(p['post_cover_img'],
                                                pformat='-cover300')
         else:
             p['post_cover_img'] = ''
         p['post_id'] = p['_id']
         p.pop('_id')
         post_list.append(p)
     self.finish(tools.dumps({'post_list': post_list}))
Exemple #4
0
 def get(self):
     """
     创建用户页面
     """
     post_id = is_oid(self.get_argument('post_id'))
     #old_post_info=get_old_tieba_post_reply(pid)
     #hots = get_hot_post()
     #if old_post_info:
     #    logging.warning("%s is an old post!"%pid)
     #    self.render('old_post.html',data=old_post_info,tieba=True,hots=hots)
     #    mdb.tieba.post.update({'url':pid},{'$set':{'last_click_time':time.time()},'$inc':{'click':1}})
     #else:
     #logging.warning("%s is a new post!"%pid)
     post_info = mdb.baidu.post.find_one({'_id': ObjectId(post_id)})
     for c in post_info['content']:
         for r in c['reply_content']:
             if r['tag'] == 'img':
                 r['content'] = tools.imgurl(r['content'], pformat='-post')
     self.finish(tools.dumps(post_info))
     mdb.baidu.post.update({'_id': ObjectId(post_id)}, {
         '$set': {
             'last_click_time': time.time()
         },
         '$inc': {
             'click': 1
         }
     })
Exemple #5
0
def get_hot_post():
    """
    获取最火的3个帖子
    """
    hots = []
    res = mdb.baidu.post.find({'is_open':settings.get('post_flag'),'post_cover_img':{'$exists':True}},sort=[('last_click_time',-1)],limit=6,fields={'_id':False,'url':True,'post_cover_img':True,'title':True})
    for p in res:
        p['post_cover_img'] = tools.imgurl(p['post_cover_img'],pformat='-cover300')
        hots.append(p)
    return hots
Exemple #6
0
 def get(self):
     page = int(self.get_argument('page',1))
     count = 30
     post_list = []
     res = mdb.baidu.post.find({'is_open':0,'post_cover_img':{'$exists':True}},sort=[('find_time',-1)],skip=(page-1)*count,limit=count,fields={'title':True,'post_cover_img':True})
     for p in res:
         #p['abstract'] = get_post_abstract(p)
         if p.get('post_cover_img'):
             p['post_cover_img'] = tools.imgurl(p['post_cover_img'],pformat='-cover300')
         else:
             p['post_cover_img']=''
         p['post_id'] = p['_id']
         p.pop('_id')
         post_list.append(p)
     self.finish(tools.dumps({'post_list':post_list}))
Exemple #7
0
 def get(self):
     """
     """
     page = int(self.get_argument('page',1))
     count = 20
     post_list = []
     res = mdb.baidu.post.find({'is_open':settings.get('post_flag')},sort=[('find_time',-1)],skip=(page-1)*count,limit=count)
     for p in res:
         p['abstract'] = get_post_abstract(p)
         if p.get('post_cover_img'):
             p['post_cover_img'] = tools.imgurl(p['post_cover_img'],pformat='-cover300')
         else:
             p['post_cover_img']=''
         post_list.append(p)
     self.render("post_list.html",posts = post_list,page = page)
Exemple #8
0
    def get(self):
        """
        """
        page = int(self.get_argument('page',1))
        album_list = mdb.baidu.post.find({'is_open':settings.get('post_flag'),'reply_img_count':{'$gt':2}},fields={'reply_img_list':True,'title':True,'_id':False},sort=[('find_time',-1)],skip=20*(page-1),limit=20)
        album_list = list(album_list)
        for idx,album in enumerate(album_list):
            pics = []
            for pic in album['reply_img_list']:
                pic = tools.imgurl(pic,pformat='-cover300') 
                #pic = tools.imgurl(pic) 
                pics.append(pic)
            album_list[idx]['pic_list'] = pics
            album_list[idx].pop('reply_img_list')

        self.finish(json.dumps({'fuli_list':album_list}))
Exemple #9
0
def get_real_reply(elements,use_qiniu=True):
    """
    将字典数据转为html
    """
    new_elements = []
    #print 'elements:',elements
    for e in elements:
        if e['tag'] == 'img':
            #是否使用七牛的图片
            if use_qiniu:
                new_e = '<img src="%s" class="img-responsive">'%tools.imgurl(e['content'],pformat='-post')
            else:
                new_e = '<img src="%s" class="img-responsive">'%(e.get('old_content','') or e.get('content','')+"?kilobug") 
        else:
            new_e = '<p>%s</p>'%e['content']
        new_elements.append(new_e)
    return ''.join(new_elements)
Exemple #10
0
def get_real_reply(elements, use_qiniu=True):
    """
    将字典数据转为html
    """
    new_elements = []
    #print 'elements:',elements
    for e in elements:
        if e['tag'] == 'img':
            #是否使用七牛的图片
            if use_qiniu:
                new_e = '<img src="%s" class="img-responsive">' % tools.imgurl(
                    e['content'], pformat='-post')
            else:
                new_e = '<img src="%s" class="img-responsive">' % (e.get(
                    'old_content', '') or e.get('content', '') + "?kilobug")
        else:
            new_e = '<p>%s</p>' % e['content']
        new_elements.append(new_e)
    return ''.join(new_elements)
Exemple #11
0
 def get(self):
     """
     """
     page = int(self.get_argument('page', 1))
     count = 20
     post_list = []
     res = mdb.baidu.post.find({'is_open': settings.get('post_flag')},
                               sort=[('find_time', -1)],
                               skip=(page - 1) * count,
                               limit=count)
     for p in res:
         p['abstract'] = get_post_abstract(p)
         if p.get('post_cover_img'):
             p['post_cover_img'] = tools.imgurl(p['post_cover_img'],
                                                pformat='-cover300')
         else:
             p['post_cover_img'] = ''
         post_list.append(p)
     self.render("post_list.html", posts=post_list, page=page)
Exemple #12
0
 def get(self):
     """
     创建用户页面
     """
     post_id = is_oid(self.get_argument('post_id'))
     #old_post_info=get_old_tieba_post_reply(pid)
     #hots = get_hot_post()
     #if old_post_info: 
     #    logging.warning("%s is an old post!"%pid)
     #    self.render('old_post.html',data=old_post_info,tieba=True,hots=hots)
     #    mdb.tieba.post.update({'url':pid},{'$set':{'last_click_time':time.time()},'$inc':{'click':1}})
     #else:
     #logging.warning("%s is a new post!"%pid)
     post_info = mdb.baidu.post.find_one({'_id':ObjectId(post_id)})
     for c in post_info['content']:
         for r in c['reply_content']:
             if r['tag'] == 'img':
                 r['content'] = tools.imgurl(r['content'],pformat='-post')
     self.finish(tools.dumps(post_info))
     mdb.baidu.post.update({'_id':ObjectId(post_id)},{'$set':{'last_click_time':time.time()},'$inc':{'click':1}})