本文整理汇总了Python中feedgen.feed.FeedGenerator.add_item方法的典型用法代码示例。如果您正苦于以下问题:Python FeedGenerator.add_item方法的具体用法?Python FeedGenerator.add_item怎么用?Python FeedGenerator.add_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedgen.feed.FeedGenerator
的用法示例。
在下文中一共展示了FeedGenerator.add_item方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
def get(self):
fg = FeedGenerator()
fg.id("http://test.ts")
fg.title("My Test Feed")
fg.icon("https://avatars1.githubusercontent.com/u/715660?v=3&s=32")
fg.author({'name': "The Author", 'email': "[email protected]"})
fg.link(href="http://example.org/index.atom?page=2", rel="next")
fg.link(href="http://test.ts", rel="alternate")
fg.logo("https://avatars1.githubusercontent.com/u/715660?v=3&s=32")
fg.description("Este é o monstro do lago 1")
fg.subtitle("This is an example feed!")
fg.language("en-us")
# Handle this:
#< sy:updatePeriod > hourly < / sy:updatePeriod >
#< sy:updateFrequency > 1 < / sy:updateFrequency >
fg.lastBuildDate(datetime.now(pytz.timezone("America/Sao_Paulo")))
fi = fg.add_item()
fi.id("http://test.ts/id/1", )
#fi.link(link="http://test.ts/id/1")
fi.title("Monstro do Lago 1")
fi.description("Este é o monstro do lago 1")
fi.comments("http://test.ts/id/1/comments")
fi.pubdate(datetime.now(pytz.timezone("America/Sao_Paulo")))
fi = fg.add_item()
fi.id("http://test.ts/id/2")
fi.title("Monstro do Lago 2")
fi.description("Este é o monstro do lago 2")
fi.pubdate(datetime.now(pytz.timezone("America/Sao_Paulo")))
#test = fg.atom_str(pretty=True)
rss_str = fg.rss_str(pretty=True)
self.set_header("Content-Type", 'application/xml; charset="utf-8"')
#self.set_header("Content-Disposition",
# "attachment; filename='test.xml'")
self.write(rss_str)
#if regexp.search(word) is not None:
# print
# 'matched'
if self.is_browser_mobile():
print("buu")
else:
print(self.request.headers["User-Agent"])
示例2: setUp
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
def setUp(self):
fg = FeedGenerator()
self.feedId = 'http://example.com'
self.title = 'Some Testfeed'
fg.id(self.feedId)
fg.title(self.title)
fg.link(href='http://lkiesow.de', rel='alternate')[0]
fg.description('...')
fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The First Episode')
fe.content(u'…')
# Use also the different name add_item
fe = fg.add_item()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The Second Episode')
fe.content(u'…')
fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The Third Episode')
fe.content(u'…')
self.fg = fg
示例3: TestExtensionTorrent
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
class TestExtensionTorrent(unittest.TestCase):
def setUp(self):
self.fg = FeedGenerator()
self.fg.load_extension('torrent')
self.fg.title('title')
self.fg.link(href='http://example.com', rel='self')
self.fg.description('description')
def test_podcastEntryItems(self):
fe = self.fg.add_item()
fe.title('y')
fe.torrent.filename('file.xy')
fe.torrent.infohash('123')
fe.torrent.contentlength('23')
fe.torrent.seeds('1')
fe.torrent.peers('2')
fe.torrent.verified('1')
assert fe.torrent.filename() == 'file.xy'
assert fe.torrent.infohash() == '123'
assert fe.torrent.contentlength() == '23'
assert fe.torrent.seeds() == '1'
assert fe.torrent.peers() == '2'
assert fe.torrent.verified() == '1'
# Check that we have the item in the resulting XML
ns = {'torrent': 'http://xmlns.ezrss.it/0.1/dtd/'}
root = etree.fromstring(self.fg.rss_str())
filename = root.xpath('/rss/channel/item/torrent:filename/text()',
namespaces=ns)
assert filename == ['file.xy']
示例4: TestExtensionDc
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
class TestExtensionDc(unittest.TestCase):
def setUp(self):
self.fg = FeedGenerator()
self.fg.load_extension('dc')
self.fg.title('title')
self.fg.link(href='http://example.com', rel='self')
self.fg.description('description')
def test_entryLoadExtension(self):
fe = self.fg.add_item()
try:
fe.load_extension('dc')
except ImportError:
pass # Extension already loaded
def test_elements(self):
for method in dir(self.fg.dc):
if method.startswith('dc_'):
m = getattr(self.fg.dc, method)
m(method)
assert m() == [method]
self.fg.id('123')
assert self.fg.atom_str()
assert self.fg.rss_str()
示例5: TestExtensionGeo
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
class TestExtensionGeo(unittest.TestCase):
def setUp(self):
self.fg = FeedGenerator()
self.fg.load_extension('geo')
self.fg.title('title')
self.fg.link(href='http://example.com', rel='self')
self.fg.description('description')
def test_geoEntryItems(self):
fe = self.fg.add_item()
fe.title('y')
fe.geo.point('42.36 -71.05')
assert fe.geo.point() == '42.36 -71.05'
# Check that we have the item in the resulting XML
ns = {'georss': 'http://www.georss.org/georss'}
root = etree.fromstring(self.fg.rss_str())
point = root.xpath('/rss/channel/item/georss:point/text()',
namespaces=ns)
assert point == ['42.36 -71.05']
示例6: TestExtensionPodcast
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
class TestExtensionPodcast(unittest.TestCase):
def setUp(self):
self.fg = FeedGenerator()
self.fg.load_extension('podcast')
self.fg.title('title')
self.fg.link(href='http://example.com', rel='self')
self.fg.description('description')
def test_category_new(self):
self.fg.podcast.itunes_category([{'cat': 'Technology',
'sub': 'Podcasting'}])
self.fg.podcast.itunes_explicit('no')
self.fg.podcast.itunes_complete('no')
self.fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss')
self.fg.podcast.itunes_owner('John Doe', '[email protected]')
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
namespaces=ns)
assert cat[0] == 'Technology'
assert scat[0] == 'Podcasting'
def test_category(self):
self.fg.podcast.itunes_category('Technology', 'Podcasting')
self.fg.podcast.itunes_explicit('no')
self.fg.podcast.itunes_complete('no')
self.fg.podcast.itunes_new_feed_url('http://example.com/new-feed.rss')
self.fg.podcast.itunes_owner('John Doe', '[email protected]')
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
cat = root.xpath('/rss/channel/itunes:category/@text', namespaces=ns)
scat = root.xpath('/rss/channel/itunes:category/itunes:category/@text',
namespaces=ns)
assert cat[0] == 'Technology'
assert scat[0] == 'Podcasting'
def test_podcastItems(self):
fg = self.fg
fg.podcast.itunes_author('Lars Kiesow')
fg.podcast.itunes_block('x')
fg.podcast.itunes_complete(False)
fg.podcast.itunes_explicit('no')
fg.podcast.itunes_image('x.png')
fg.podcast.itunes_subtitle('x')
fg.podcast.itunes_summary('x')
assert fg.podcast.itunes_author() == 'Lars Kiesow'
assert fg.podcast.itunes_block() == 'x'
assert fg.podcast.itunes_complete() == 'no'
assert fg.podcast.itunes_explicit() == 'no'
assert fg.podcast.itunes_image() == 'x.png'
assert fg.podcast.itunes_subtitle() == 'x'
assert fg.podcast.itunes_summary() == 'x'
# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
author = root.xpath('/rss/channel/itunes:author/text()', namespaces=ns)
assert author == ['Lars Kiesow']
def test_podcastEntryItems(self):
fe = self.fg.add_item()
fe.title('y')
fe.podcast.itunes_author('Lars Kiesow')
fe.podcast.itunes_block('x')
fe.podcast.itunes_duration('00:01:30')
fe.podcast.itunes_explicit('no')
fe.podcast.itunes_image('x.png')
fe.podcast.itunes_is_closed_captioned('yes')
fe.podcast.itunes_order(1)
fe.podcast.itunes_subtitle('x')
fe.podcast.itunes_summary('x')
assert fe.podcast.itunes_author() == 'Lars Kiesow'
assert fe.podcast.itunes_block() == 'x'
assert fe.podcast.itunes_duration() == '00:01:30'
assert fe.podcast.itunes_explicit() == 'no'
assert fe.podcast.itunes_image() == 'x.png'
assert fe.podcast.itunes_is_closed_captioned()
assert fe.podcast.itunes_order() == 1
assert fe.podcast.itunes_subtitle() == 'x'
assert fe.podcast.itunes_summary() == 'x'
# Check that we have the item in the resulting XML
ns = {'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd'}
root = etree.fromstring(self.fg.rss_str())
author = root.xpath('/rss/channel/item/itunes:author/text()',
namespaces=ns)
assert author == ['Lars Kiesow']
示例7: TestExtensionMedia
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import add_item [as 别名]
class TestExtensionMedia(unittest.TestCase):
def setUp(self):
self.fg = FeedGenerator()
self.fg.load_extension('media')
self.fg.id('id')
self.fg.title('title')
self.fg.link(href='http://example.com', rel='self')
self.fg.description('description')
def test_media_content(self):
fe = self.fg.add_item()
fe.id('id')
fe.title('title')
fe.content('content')
fe.media.content(url='file1.xy')
fe.media.content(url='file2.xy')
fe.media.content(url='file1.xy', group=2)
fe.media.content(url='file2.xy', group=2)
fe.media.content(url='file.xy', group=None)
ns = {'media': 'http://search.yahoo.com/mrss/',
'a': 'http://www.w3.org/2005/Atom'}
# Check that we have the item in the resulting RSS
root = etree.fromstring(self.fg.rss_str())
url = root.xpath('/rss/channel/item/media:group/media:content[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
# There is one without a group
url = root.xpath('/rss/channel/item/media:content[1]/@url',
namespaces=ns)
assert url == ['file.xy']
# Check that we have the item in the resulting Atom feed
root = etree.fromstring(self.fg.atom_str())
url = root.xpath('/a:feed/a:entry/media:group/media:content[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
fe.media.content(content=[], replace=True)
assert fe.media.content() == []
def test_media_thumbnail(self):
fe = self.fg.add_item()
fe.id('id')
fe.title('title')
fe.content('content')
fe.media.thumbnail(url='file1.xy')
fe.media.thumbnail(url='file2.xy')
fe.media.thumbnail(url='file1.xy', group=2)
fe.media.thumbnail(url='file2.xy', group=2)
fe.media.thumbnail(url='file.xy', group=None)
ns = {'media': 'http://search.yahoo.com/mrss/',
'a': 'http://www.w3.org/2005/Atom'}
# Check that we have the item in the resulting RSS
root = etree.fromstring(self.fg.rss_str())
url = root.xpath(
'/rss/channel/item/media:group/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
# There is one without a group
url = root.xpath('/rss/channel/item/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file.xy']
# Check that we have the item in the resulting Atom feed
root = etree.fromstring(self.fg.atom_str())
url = root.xpath('/a:feed/a:entry/media:group/media:thumbnail[1]/@url',
namespaces=ns)
assert url == ['file1.xy', 'file1.xy']
fe.media.thumbnail(thumbnail=[], replace=True)
assert fe.media.thumbnail() == []