Python Feedpoller Example

说明

python feedpoller示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Python

命名空间/包名称: pluginsfeedretrieverfeedretriever

示例#1
文件: test_runkeeper_feed.py项目: Tigge/platinumshrimp

    def test_runkeeper_multiple_updates(self, read):
        def on_entry1(feed, entry):
            self.assertEqual(entry.title, "Walking Activity on 2016-07-11 07:45:01")
            self.assertEqual(entry.link, "https://runkeeper.com/user/mikesir87/activity/823368881")
            self.updated = True

        def on_entry2(feed, entry):
            self.assertEqual(entry.title, "Walking Activity on 2016-07-11 17:33:27")
            self.assertEqual(entry.link, "https://runkeeper.com/user/mikesir87/activity/823715917")
            self.updated = True

        def on_entry(feed, entry):
            self.on_entry(feed, entry)

        read.return_value = feedparse(os.path.join(self.dir, "runkeeper_rss_0-entries.xml"))
        poller = Feedpoller({"url": "MOCK_URL", "title": "Test"},
                            on_created=noop, on_entry=on_entry, on_error=self.fail)

        self.updated = False
        self.on_entry = on_entry1
        read.return_value = feedparse(os.path.join(self.dir, "runkeeper_rss_1-entries.xml"))
        poller.update_now()
        self.assertTrue(self.updated)

        self.updated = False
        self.on_entry = on_entry2
        read.return_value = feedparse(os.path.join(self.dir, "runkeeper_rss_2-entries.xml"))
        poller.update_now()
        self.assertTrue(self.updated)

示例#2
文件: test_basic_feed.py项目: Tigge/platinumshrimp

    def test_initial_update(self, read):
        read.return_value = feedparse(os.path.join(self.dir, "basic_rss_0-entries.xml"))

        def on_entry(feed, entry):
            self.assertEqual(entry.title, "Test Title")
            self.assertEqual(entry.link, "http://www.example.com")
            self.updated = True

        feed = Feedpoller({'url': 'MOCK_URL', 'title': "Test"},
                          on_created=noop, on_entry=on_entry, on_error=self.fail)
        self.updated = False

        read.return_value = feedparse(os.path.join(self.dir, "basic_rss_1-entries.xml"))
        feed.update_now()
        self.assertTrue(self.updated)

示例#3
文件: test_runkeeper_feed.py项目: Tigge/platinumshrimp

 def test_runkeeper_no_update(self, read):
     read.return_value = feedparse(os.path.join(self.dir, "runkeeper_rss_0-entries.xml"))
     poller = Feedpoller({"url": "MOCK_URL", "title": "Runkeeper Feed"},
                         on_created=noop, on_entry=self.fail, on_error=self.fail)
     poller.update_now()

示例#4
文件: test_basic_feed.py项目: Tigge/platinumshrimp

 def test_no_update(self, read):
     read.return_value = feedparse(os.path.join(self.dir, "basic_rss_0-entries.xml"))
     feed = Feedpoller({'url': "MOCK_URL", "title": "MOCK_TITLE"},
                       on_created=noop, on_entry=self.fail, on_error=self.fail)
     feed.update_now()

展开阅读全文