本文整理汇总了Python中feedgen.feed.FeedGenerator.entry方法的典型用法代码示例。如果您正苦于以下问题:Python FeedGenerator.entry方法的具体用法?Python FeedGenerator.entry怎么用?Python FeedGenerator.entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedgen.feed.FeedGenerator
的用法示例。
在下文中一共展示了FeedGenerator.entry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_removeEntryByIndex
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import entry [as 别名]
def test_removeEntryByIndex(self):
fg = FeedGenerator()
self.feedId = 'http://example.com'
self.title = 'Some Testfeed'
fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The Third Episode')
assert len(fg.entry()) == 1
fg.remove_entry(0)
assert len(fg.entry()) == 0
示例2: generate_nhk_easy_news_feed
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import entry [as 别名]
async def generate_nhk_easy_news_feed(
entry_count=ENTRY_COUNT,
return_content_only=False,
):
feed_items = []
fg = FeedGenerator()
fg.id('https://www.reddit.com/r/NHKEasyNews')
fg.title('NHK Easy News')
fg.language('ja')
feed = feedparser.parse(
'https://www.reddit.com/r/NHKEasyNews.rss?limit={}'
.format(entry_count))
reddit = praw.Reddit(
client_id=settings.REDDIT_CLIENT_ID,
client_secret=settings.REDDIT_CLIENT_SECRET,
username=settings.REDDIT_CLIENT_USERNAME,
password=settings.REDDIT_CLIENT_PASSWORD,
user_agent='Manabi Reader',
)
entries = []
for post in reversed(feed.entries):
if 'discord server' in post.title.lower():
continue
reddit_content = post.content[0].value
nhk_url_match = re.search(
r'(http://www3.nhk.or.jp/news/easy/.*?\.html)', reddit_content)
if nhk_url_match is None:
continue
nhk_url = nhk_url_match.group()
for attempt in range(ATTEMPTS_PER_ENTRY):
session = AsyncHTMLSession()
r = await session.get(nhk_url, timeout=60)
await r.html.arender(keep_page=True)
try:
entry = await _process_and_add_entry(
post, nhk_url, r, fg, reddit)
except NoArticleBodyError:
if attempt < ATTEMPTS_PER_ENTRY - 1:
continue
raise
if entry is not None:
entries.append(entry)
#r.html.page.close()
await session.close()
break
if entry is None:
continue
if return_content_only:
html = ''
for entry in reversed(entries):
title = entry.title()
content = entry.content()['content']
html += f'<h1>{title}</h1>{content}'
return html
if fg.entry() == 0:
raise Exception("Generated zero feed entries from NHK Easy News.")
return fg.atom_str(pretty=True, encoding='utf-8')
示例3: test_setEntries
# 需要导入模块: from feedgen.feed import FeedGenerator [as 别名]
# 或者: from feedgen.feed.FeedGenerator import entry [as 别名]
def test_setEntries(self):
fg2 = FeedGenerator()
fg2.entry(self.fg.entry())
assert len(fg2.entry()) == 3
assert self.fg.entry() == fg2.entry()