Ejemplo n.º 1
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        # 上次看到哪条?
        start = time.time()
        last = public_db.getLast(self.current_user)
        if last:
            last_message_id = last.last_message_id
            limit = None  # 查出看到上次的所有
        else:
            last_message_id = None
            limit = 100  # 第一次看,就查最新的10条出来

        messages = public_db.getMessages(user_id=self.current_user,
                                         last_message_id=last_message_id,
                                         limit=limit)
        if len(messages) > 500:
            messages = list(messages)[:499]
        end = time.time()
        print end - start
        self.write(
            json.dumps(
                {
                    'error': '0',
                    'messages': messages,
                    'last_message_id': last_message_id
                },
                cls=public_bz.ExtEncoder))
Ejemplo n.º 2
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        data = json.loads(self.request.body)

        god_name = data.get('god_name')
        offset = data.get('offset', None)

        messages = public_db.getMessages(god_name=god_name, offset=offset)

        self.write(json.dumps({'error': '0', 'messages': messages}, cls=public_bz.ExtEncoder))
Ejemplo n.º 3
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        data = json.loads(self.request.body)

        offset = data.get('offset')
        user_id = self.current_user  # 当前用户关注了的

        messages = public_db.getMessages(user_id=user_id, offset=offset)

        self.write(json.dumps({'error': '0', 'messages': messages}, cls=public_bz.ExtEncoder))
Ejemplo n.º 4
0
def getMessages(limit=None, current_user=None, god_name=None, offset=None, last_time=None):
    '''
    create by bigzhu at 15/08/03 13:24:39 分页方式取messages
    '''
    anchor = ''
    if limit is None:
        limit = 20
        more = 40
    messages = list(public_db.getMessages(current_user, limit=limit, god_name=god_name, offset=offset, last_time=last_time))
    if messages:
        anchor_message = messages[-1]
        anchor = '%s_%s' % (anchor_message.m_type, anchor_message.id)
        more = int(limit) + 20
    return messages, more, anchor
Ejemplo n.º 5
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        data = json.loads(self.request.body)

        offset = data.get('offset')
        user_id = self.current_user  # 当前用户关注了的

        messages = public_db.getMessages(user_id=user_id, offset=offset)

        self.write(
            json.dumps({
                'error': '0',
                'messages': messages
            },
                       cls=public_bz.ExtEncoder))
Ejemplo n.º 6
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        # 上次看到哪条?
        last = public_db.getLast(self.current_user)
        if last:
            last_message_id = last.last_message_id
            last_time = last.last_time
            limit=None #查出看到上次的所有
        else:
            last_message_id = None
            last_time = None
            limit=10 #第一次看,就查最新的10条出来

        messages = public_db.getMessages(user_id=self.current_user, last_time=last_time, limit=limit)

        #print datetime.datetime.now()
        self.write(json.dumps({'error': '0', 'messages': messages, 'last_message_id': last_message_id}, cls=public_bz.ExtEncoder))
Ejemplo n.º 7
0
    def post(self):
        #import datetime
        #print datetime.datetime.now()
        self.set_header("Content-Type", "application/json")
        user_id = self.current_user
        # 上次看到哪条?
        last = public_db.getLast(user_id)
        if last:
            last_message_id = last.last_message_id
            last_time = last.last_time
        else:
            last_message_id = None
            last_time = None

        messages = public_db.getMessages(user_id=user_id, last_time=last_time, limit=None)

        #print datetime.datetime.now()
        self.write(json.dumps({'error': '0', 'messages': messages, 'last_message_id': last_message_id}, cls=public_bz.ExtEncoder))
Ejemplo n.º 8
0
    def post(self):
        self.set_header("Content-Type", "application/json")
        data = json.loads(self.request.body)

        god_name = data.get('god_name')
        offset = data.get('offset', None)
        limit = data.get('limit', None)
        if limit is None:
            limit = 50
        messages = public_db.getMessages(god_name=god_name,
                                         offset=offset,
                                         limit=limit)

        self.write(
            json.dumps({
                'error': '0',
                'messages': messages
            },
                       cls=public_bz.ExtEncoder))
Ejemplo n.º 9
0
def getMessages(limit=None,
                current_user=None,
                god_name=None,
                offset=None,
                last_message_id=None):
    '''
    create by bigzhu at 15/08/03 13:24:39 分页方式取messages
    '''
    anchor = ''
    if limit is None:
        limit = 20
        more = 40
    messages = list(
        public_db.getMessages(current_user,
                              limit=limit,
                              god_name=god_name,
                              offset=offset,
                              last_message_id=last_message_id))
    if messages:
        anchor_message = messages[-1]
        anchor = '%s_%s' % (anchor_message.m_type, anchor_message.id)
        more = int(limit) + 20
    return messages, more, anchor
Ejemplo n.º 10
0
 def get(self):
     type = self.get_argument('t', None, True)
     id = self.get_argument('id', None, True)
     messages = public_db.getMessages(type=type, id=id)
     self.render(tornado_bz.getTName(self, "main"), messages=messages)
Ejemplo n.º 11
0
 def get(self):
     type = self.get_argument('t', None, True)
     id = self.get_argument('id', None, True)
     messages = public_db.getMessages(type=type, id=id)
     self.render(tornado_bz.getTName(self, "main"), messages=messages)