Beispiel #1
0
    def create_feed(self, url, hub=None, find_feed=True):
        """
        Creates a Feed, searching the website for a feed and PuSH links if find_feed is True.

        :param url: The URL of a website or feed.
        :param hub: The URL of the PuSH hub to use.
        :param find_feed: Set to True to search the website for a feed and override the url
            if feed is found.
        :return: Feed
        """
        topic = url
        parsed_feed = None

        if find_feed:
            app.logger.info(u'Finding feed for url {0}'.format(url))
            data = get_feed(url)
            app.logger.info(u'Found feed {0} with hub {1} for url {2}'
                            .format(data[1], data[0], url))
            if data[0]:
                if not hub:
                    hub = data[0]
            if data[1]:
                topic = data[1]
            if data[2]:
                parsed_feed = data[2]

        if not hub:
            hub = app.config['DEFAULT_HUB']

        app.logger.info(u'Creating Feed with topic {0} and hub {1}'
                        .format(topic, hub))
        feed = Feed(topic=topic, hub=hub)

        if parsed_feed:
            try:
                url = parsed_feed.feed['link']
                domain = get_domain(url)
                if domain:
                    app.logger.info('Set site_url for Feed {0} to {1}'
                                    .format(feed, domain))
                    feed.site_url = domain
            except:
                pass

        db.session.add(feed)

        if parsed_feed:
            app.logger.info(u'Feed creation for topic {0} parsed a feed, '
                            'sending notification'.format(topic))
            notification_received.send(self,
                                       feed=feed,
                                       content_type='application/rss+xml',
                                       content=parsed_feed,
                                       parsed=True)

        db.session.commit()
        return feed
Beispiel #2
0
 def test_get_pubsub_links_no_hub(self):
     links = get_feed('davidbeath.com')
     self.assertIsNone(links[0])
     self.assertEqual(links[1], 'https://davidbeath.com/rss.xml')
     self.assertIsNotNone(links[2])
     self.assertEqual(links[2].feed.title, 'David Beath')
Beispiel #3
0
 def test_get_feed_raises_error(self):
     with self.assertRaises(GetFeedError):
         get_feed('asdf')
Beispiel #4
0
 def test_get_pubsub_links(self):
     links = get_feed('blog.superfeedr.com')
     self.assertEqual(links[0], 'http://pubsubhubbub.superfeedr.com/')
     self.assertEqual(links[1],
                      'https://superfeedr-blog-feed.herokuapp.com/')
     self.assertIsNotNone(links[2])