Example #1
0
    def set_opml(self, id):
        composite = Composite.get(id, ctx)
        if composite is None:
            abort(404)

        opml_data = get_posted_data()
        try:
            feeds = set(feeds_in_opml(opml_data))
        except:
            import traceback

            log.error(traceback.format_exc())
            abort(400)

        result = defaultdict(list)
        oldfeeds = set(i.url for i in composite.subscriptions.itervalues())
        remove = oldfeeds - feeds
        for url in remove:
            feed = RemoteFeed.get_by_url(url, ctx)
            if feed is not None:
                composite.unsubscribe(feed)
                result["unsubscribed"].append(url)
                log.debug('Unsubscribed composite "%s" from %s' % (id, url))
            else:
                result["unsubscribe_failed"].append(url)
                log.error('Expected composite "%s" to have RemoteFeed for %s' % (id, url))

        for url in feeds:
            if url not in oldfeeds:
                feed = get_or_immediate_create_by_url(url, ctx)
                if feed is None:
                    result["subscribe_failed"].append(url)
                    log.warn("Could not get or create feed for %s" % url)
                    continue
                composite.subscribe(feed)
                result["subscribed"].append(url)
                log.debug('Subscribed composite "%s" to %s' % (id, url))
            else:
                result["unchanged"].append(url)

        composite.save()
        log.debug('Composite "%s" saved' % id)
        return json_response(result)
Example #2
0
    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)