def get_feed_info(id): bucket = NewsBucket.get(id, ctx) if bucket is None: abort(404) feed = Dibject() feed.id = id feed.title = bucket.title feed.timestamp = bucket.last_modification_date or datetime.utcnow() try: limit = int(request.params.get('limit', DEFAULT_FEED_SIZE)) except: limit = DEFAULT_FEED_SIZE limit = min(limit, MAX_FEED_SIZE) feed.entries = _bucket_latest_entries_batch(bucket, limit=limit) return feed
def get_batch(self, id): bucket = NewsBucket.get(id, ctx) if bucket is None: abort(404) batch_args = _get_batch_args() entries, next = _bucket_latest_entries_batch(bucket, **batch_args) batch = Dibject(next=next) if request.is_xhr: # this html section can be optionally omitted by specifying # the query argument no_html=True if not asbool(request.params.get('no_html', False)): batch.html = render_entries_html(entries) batch.entries = [i.item_id for i in entries] return json_response(batch) else: batch.entries = entries return self._show_batch(id, batch)
def item_trace(e): """ produces a compact subset of the information in a news item suitable for summary or preview. html is stripped and long fields are trimmed. """ trace = Dibject() trace.timestamp = find_best_timestamp(e) or datetime.utcnow() trace.title = stripped_content(e.get('title_detail', None), 128) trace.author = trimmed(find_author_name(e), 128) trace.link = find_best_permalink(e) source = e.get('source', {}) trace.source_url = find_source_url(source) trace.source_title = stripped_content(source.get('title_detail', None), 128) content = e.get('content', [None])[0] if content is None: content = e.get('summary_detail', None) trace.summary = stripped_content(content, 256) return trace