当前位置: 首页>>代码示例>>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;未经允许,请勿转载。