當前位置: 首頁>>代碼示例>>Python>>正文


Python Importer.import_feeds方法代碼示例

本文整理匯總了Python中importer.Importer.import_feeds方法的典型用法代碼示例。如果您正苦於以下問題:Python Importer.import_feeds方法的具體用法?Python Importer.import_feeds怎麽用?Python Importer.import_feeds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在importer.Importer的用法示例。


在下文中一共展示了Importer.import_feeds方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup

# 需要導入模塊: from importer import Importer [as 別名]
# 或者: from importer.Importer import import_feeds [as 別名]
class TestImporter:
    def setup(self):
        self.engine = create_engine('sqlite://')
        self.Session = sessionmaker()
        self.Session.configure(bind=self.engine)
        Base.metadata.create_all(self.engine)

        self.importer = Importer()
        self.importer.dataAccess.Session = self.Session

        self.entry1 = Expando()
        self.entry1.title = u'entry 1 title é'
        self.entry1.description = u'entry 1 description é'
        self.entry1.link = u'http://entry1.linké'

        self.entry2 = Expando()
        self.entry2.title = u'entry 2 title é'
        self.entry2.description = u'entry 2 description é'
        self.entry2.link = self.entry1.link

        self.entry3 = Expando()
        self.entry3.title = u'entry 3 title é'
        self.entry3.description = u'entry 3 description é'
        self.entry3.link = u'http://entry3.linké'

        self.entry4 = Expando()
        self.entry4.title = u'entry 4 title é'
        self.entry4.description = u'entry 4 description é'
        self.entry4.link = u'http://entry4.linké'

        self.entry5 = Expando()
        self.entry5.title = u'entry 4 title é'
        self.entry5.link = u'http://entry4.linké'

        self.feed1 = u'http://feed1url.urlé'
        self.feed2 = u'http://feed2url.urlé'

        self.feed1contents = Expando()
        self.feed1contents.entries = [self.entry1, self.entry2]
        self.feed2contents = Expando()
        self.feed2contents.entries = [self.entry3, self.entry4]

    def teardown(self):
        Base.metadata.drop_all(self.engine)

    def test_process_newSubmission_isSaved(self):
        self.importer.process(self.entry1, self.feed1)

        saved = self.Session().query(Submission).first()
        assert saved.title == self.entry1.title
        assert saved.description == self.entry1.description
        assert saved.url == self.entry1.link
        assert saved.feed == self.feed1
        assert saved.created != None

    def test_process_submissionWithExistingLink_isNotSaved(self):
        self.importer.process(self.entry1, self.feed1)
        self.importer.process(self.entry2, self.feed2)

        assert self.Session().query(Submission).count() == 1

    def test_process_submissionWithNoDescription_isSaved(self):
        self.importer.process(self.entry5, self.feed1)

        assert self.Session().query(Submission).count() == 1

    def test_importFeeds_entriesAreSaved(self):
        self.importer.parse_feed = Mock(
            side_effect=[self.feed1contents, self.feed2contents])
        self.importer.process = MagicMock()

        self.importer.import_feeds([self.feed1, self.feed2])

        self.importer.process.assert_has_calls(
            [call(self.entry1, self.feed1),
             call(self.entry2, self.feed1),
             call(self.entry3, self.feed2),
             call(self.entry4, self.feed2)])
開發者ID:maroth,項目名稱:chreddit,代碼行數:80,代碼來源:test_importer.py

示例2: Importer

# 需要導入模塊: from importer import Importer [as 別名]
# 或者: from importer.Importer import import_feeds [as 別名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
from importer import Importer
from submitter import Submitter
from feeds import feeds

parser = argparse.ArgumentParser(description='Start chreddit tasks')
parser.add_argument('taskname', metavar='task_name', help='The name of the task to run')
args = parser.parse_args()

if (args.taskname) == 'import':
    importer = Importer()
    importer.import_feeds(feeds)

if (args.taskname) == 'submit':
    submitter = Submitter()
    submitter.login()
    submitter.submit_all_unsubmitted()

開發者ID:maroth,項目名稱:chreddit,代碼行數:22,代碼來源:tasks.py


注:本文中的importer.Importer.import_feeds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。