Exemplo n.º 1
0
  def POST(self):
    input = web.input(i=[])

    item_refs = []
    for item_id_decimal_form in input.i:
      item_refs.append(base.api.ItemRef(
          base.api.item_id_from_decimal_form(item_id_decimal_form),
          timestamp_usec=0))

    return self._fetch_render_item_refs(input.rs, item_refs, continuation=None)
Exemplo n.º 2
0
    def POST(self):
        input = web.input(i=[])

        item_refs = []
        for item_id_decimal_form in input.i:
            item_refs.append(
                base.api.ItemRef(
                    base.api.item_id_from_decimal_form(item_id_decimal_form),
                    timestamp_usec=0))

        return self._fetch_render_item_refs(input.rs,
                                            item_refs,
                                            continuation=None)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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
      ]
    })
Exemplo n.º 6
0
  def GET(self):
    try:
      recommendations_json = self._read_json_data_file('recommendations.json')
    except:
      logging.warning('Could not load preferences, using empty list',
          exc_info=True)
      recommendations_json = []

    recommendations = [
        base.api.Recommendation.from_json(r) for r in recommendations_json]
    count = int(web.input(n=4).n)
    if count < len(recommendations):
      recommendations = recommendations[:count]

    return json.dumps({
      'recs': [
        {
          'streamId': r.stream_id,
          'title': r.title,
          'snippet': '',
          'impressionTime': 0,
        } for r in recommendations
      ]
    })
Exemplo n.º 7
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]
        })
Exemplo n.º 8
0
    def GET(self):
        try:
            recommendations_json = self._read_json_data_file(
                'recommendations.json')
        except:
            logging.warning('Could not load preferences, using empty list',
                            exc_info=True)
            recommendations_json = []

        recommendations = [
            base.api.Recommendation.from_json(r) for r in recommendations_json
        ]
        count = int(web.input(n=4).n)
        if count < len(recommendations):
            recommendations = recommendations[:count]

        return json.dumps({
            'recs': [{
                'streamId': r.stream_id,
                'title': r.title,
                'snippet': '',
                'impressionTime': 0,
            } for r in recommendations]
        })
Exemplo n.º 9
0
 def GET(self):
   input = web.input()
   return render.embed_iframe(
       src=input.src, width=input.width, height=input.height)
Exemplo n.º 10
0
 def GET(self):
   input = web.input()
   return render.embed_iframe(
       src=input.src, width=input.width, height=input.height)