示例#1
0
    def GET(self, stream_id):
        stream_id = urllib.unquote_plus(stream_id)
        input = web.input(n=20, c=0, r='d')
        count = int(input.n)
        continuation = int(input.c)
        ranking = input.r

        # The read and starred items stream don't display a sorting UI, so they'll
        # always be requested in the newest-first order. We instead support
        # generating a URL that will include the desired sorting in the stream ID
        if stream_id.endswith('-oldest-first'):
            stream_id = stream_id[:-13]
            ranking = 'o'

        if stream_id.startswith('user/-/'):
            stream_id = 'user/' + web.config.reader_user_info.user_id + stream_id[
                6:]

        stream_items = web.config.reader_stream_items_by_stream_id.get(
            stream_id)
        if not stream_items:
            return web.notfound('Stream ID %s was not archived' % stream_id)

        item_refs = []
        if ranking != 'o':
            start_index = continuation
            end_index = continuation + count
        else:
            start_index = -continuation - count
            end_index = -continuation if continuation else None
        chunk_stream_item_ids = stream_items[0][start_index:end_index]
        chunk_stream_item_timestamps = stream_items[1][start_index:end_index]
        if ranking == 'o':
            chunk_stream_item_ids = tuple(reversed(chunk_stream_item_ids))
            chunk_stream_item_timestamps = tuple(
                reversed(chunk_stream_item_timestamps))

        for item_id_int_form, timestamp_usec in itertools.izip(
                chunk_stream_item_ids, chunk_stream_item_timestamps):
            item_id = base.api.ItemId(int_form=item_id_int_form)
            item_refs.append(
                base.api.ItemRef(item_id=item_id,
                                 timestamp_usec=timestamp_usec))

        next_continuation = continuation + count \
            if continuation + count < len(stream_items[0]) else None
        return self._fetch_render_item_refs(stream_id, item_refs,
                                            next_continuation)
示例#2
0
  def GET(self, stream_id):
    stream_id = urllib.unquote_plus(stream_id)
    input = web.input(n=20, c=0, r='d')
    count = int(input.n)
    continuation = int(input.c)
    ranking = input.r

    # The read and starred items stream don't display a sorting UI, so they'll
    # always be requested in the newest-first order. We instead support
    # generating a URL that will include the desired sorting in the stream ID
    if stream_id.endswith('-oldest-first'):
      stream_id = stream_id[:-13]
      ranking = 'o'

    if stream_id.startswith('user/-/'):
      stream_id = 'user/' + web.config.reader_user_info.user_id + stream_id[6:]

    stream_items = web.config.reader_stream_items_by_stream_id.get(stream_id)
    if not stream_items:
      return web.notfound('Stream ID %s was not archived' % stream_id)

    item_refs = []
    if ranking != 'o':
      start_index = continuation
      end_index = continuation + count
    else:
      start_index = -continuation - count
      end_index = -continuation if continuation else None
    chunk_stream_item_ids = stream_items[0][start_index:end_index]
    chunk_stream_item_timestamps = stream_items[1][start_index:end_index]
    if ranking == 'o':
      chunk_stream_item_ids = tuple(reversed(chunk_stream_item_ids))
      chunk_stream_item_timestamps = tuple(reversed(chunk_stream_item_timestamps))

    for item_id_int_form, timestamp_usec in itertools.izip(
        chunk_stream_item_ids, chunk_stream_item_timestamps):
      item_id = base.api.ItemId(int_form=item_id_int_form)
      item_refs.append(
          base.api.ItemRef(item_id=item_id, timestamp_usec=timestamp_usec))

    next_continuation = continuation + count \
        if continuation + count < len(stream_items[0]) else None
    return self._fetch_render_item_refs(stream_id, item_refs, next_continuation)
示例#3
0
  def GET(self):
    input = web.input(r='d')
    stream_id = input.s
    count = int(input.n)
    ranking = input.r

    stream_items = web.config.reader_stream_items_by_stream_id.get(stream_id)
    if not stream_items:
      return web.notfound('Stream ID %s was not archived' % stream_id)

    item_refs = [
      base.api.ItemRef(base.api.ItemId(item_id_int_form), timestamp_usec)
      for item_id_int_form, timestamp_usec in itertools.izip(*stream_items)
    ]

    return json.dumps({
      'itemRefs': [
        {
          'id': item_ref.item_id.decimal_form,
          'timestampUsec': item_ref.timestamp_usec,
          'directStreamIds': [],
        } for item_ref in item_refs
      ]
    })
示例#4
0
    def GET(self):
        input = web.input(r='d')
        stream_id = input.s
        count = int(input.n)
        ranking = input.r

        stream_items = web.config.reader_stream_items_by_stream_id.get(
            stream_id)
        if not stream_items:
            return web.notfound('Stream ID %s was not archived' % stream_id)

        item_refs = [
            base.api.ItemRef(base.api.ItemId(item_id_int_form), timestamp_usec)
            for item_id_int_form, timestamp_usec in itertools.izip(
                *stream_items)
        ]

        return json.dumps({
            'itemRefs': [{
                'id': item_ref.item_id.decimal_form,
                'timestampUsec': item_ref.timestamp_usec,
                'directStreamIds': [],
            } for item_ref in item_refs]
        })