예제 #1
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}))
예제 #2
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
         }
     })
예제 #3
0
 def sendline(self, response={}):
     """return an api response in the proper output format with status_code == 200"""
     self.set_header("Content-Type", "application/json; charset=UTF-8")
     #self.ret['para'] = response
     if not response.get('status'):
         response['status'] = 1
     data = tools.dumps(response)
     logging.info('==================================================')
     logging.info('>>>>>>>response:%s'%data)
     logging.info('==================================================\n\n')
     print 'data:',data
     self.finish(data)
예제 #4
0
 def sendline(self, response={}):
     """return an api response in the proper output format with status_code == 200"""
     self.set_header("Content-Type", "application/json; charset=UTF-8")
     #self.ret['para'] = response
     if not response.get('status'):
         response['status'] = 1
     data = tools.dumps(response)
     logging.info('==================================================')
     logging.info('>>>>>>>response:%s' % data)
     logging.info('==================================================\n\n')
     print 'data:', data
     self.finish(data)
예제 #5
0
 def senderror(self, reason='',status=0):
     """
     发送报错
     @response_status 0:请求报错
                      -1:未注册
     """
     self.set_header("Content-Type", "application/text; charset=UTF-8")
     data = {'status':status,'reason':reason}
     encode_data = tools.dumps(data)
     logging.error('==================================================')
     logging.error('>>>>>>>response:%s'%data)
     logging.error('==================================================\n\n')
     self.finish(encode_data)
예제 #6
0
 def senderror(self, reason='', status=0):
     """
     发送报错
     @response_status 0:请求报错
                      -1:未注册
     """
     self.set_header("Content-Type", "application/text; charset=UTF-8")
     data = {'status': status, 'reason': reason}
     encode_data = tools.dumps(data)
     logging.error('==================================================')
     logging.error('>>>>>>>response:%s' % data)
     logging.error('==================================================\n\n')
     self.finish(encode_data)
예제 #7
0
    def reducer(self, state, action):
        ''' job of this one is to build a new state for the store, based on its
        current state and an action with type and state data '''
        console.log('reducer, type:', action.type, 'action.data:')
        dumps(action.data)

        ns = {'route': {}}        # new state - from old state:
        ns.update(state)
        # and action data:
        if not action.data:
            # init:
            return ns

        ns['action'] = action.type
        if action.type == 'route_update':
            return self.reduce_route_update(ns, action)

        # normal state changes:
        for comp_id, kv in action.data.items():
            #if action.type == 'life_cycle':
            #    if len(d.unmount):
            #        # kick its id from the new state, so that by the observer
            #        # it will be unmounted:
            #        for id in d.unmount:
            #            if id in ns:
            #                del ns[id]
            #        continue

            comp = self.components_by_id[comp_id]
            # for comps we know copy level, theirs are flat:
            if comp:
                cstate = comp.state
                cns = {} # new component state
                cns.update(cstate)
                cns.update(kv)
                cns['_id_'] += 1
                ns[comp_id] = cns
        return ns
예제 #8
0
파일: server.py 프로젝트: pakoo/shantie
 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}))
예제 #9
0
파일: app.py 프로젝트: pakoo/shantie
def get_mlg_pm():
    shanghai = db.find_one({'location':'shanghai'},sort=[('create_time',-1)])    
    beijing = db.find_one({'location':'beijing'},sort=[('create_time',-1)])    
    guangzhou = db.find_one({'location':'guangzhou'},sort=[('create_time',-1)])    
    chengdu = db.find_one({'location':'chengdu'},sort=[('create_time',-1)])    
    shanghai['location'] = u'上海'
    shanghai['level'] = get_level2(int(shanghai.get('data','暂无数据')))
    beijing['location'] = u'北京'
    beijing['level'] = get_level2(int(beijing.get('data','暂无数据')))
    guangzhou['location'] = u'广州'
    guangzhou['level'] = get_level2(int(guangzhou.get('data','暂无数据')))
    chengdu['location'] = u'成都'
    chengdu['level'] = get_level2(int(chengdu.get('data','暂无数据')))
    res = tools.dumps([shanghai,beijing,guangzhou,chengdu])
    return res
예제 #10
0
파일: server.py 프로젝트: pakoo/shantie
 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}})